HEY YOU!!!, Our records indicate that you have never posted to our site before! Why not make your first post today by saying hello to our community in our new people forums. To access all the good good stuff you need to post, post, and post more.


Support Webrats Forum with your Subscription. Only $5.95 per month!
Adult lounge Access • Private Messaging • GAMES •
Please click here for more details • Please click here to subscribe
Go Back   WR > Community > Computers and Programming
User Name
Password
Register Help Desk Music Uploads Live Cams Arcade Upgrade Account Mark Forums Read
Reply
 
Thread Tools
Old 07-08-2008, 02:39 AM   #1
shocking4life
whore
 
 
Join Date: Jul 2006
Location: CA
Posts: 220/0.27
Threads: 6
United States MALE
Hey guys looking for some Java help

click on one of our sponsors! OR REMOVE ADS
Im coding this application and I cant figure out how to make the last bit to work. It asks for user input in a loop until they do not want to input any more entries, it should then use the entered data to calculate a total and averages.

From what i have it just uses the last entry from the loop and not the entire loop. Any help would be appreciated, thanks!

To sum up the program will:
* Ask whether the consultant is a partner (y/n)
* Asks for employee hours
* Calculate the total cost for the employee
* Output the Employee type, Employee Hours and Employee Cost
* Repeat if desired
Then it will: (heres where im having trouble)
*Tabulate the total number of employees
* Tabulate the total project cost
* Calulate the average hours per employee
* Calculate the average project hourly billing rate
and output it to the console.


Code:
import java.text.NumberFormat; import java.util.Scanner; public class BillingAppp { public static void main(String[] args) { // welcome the user to the program System.out.println("Weclome to the Billing Application"); System.out.println(); // print a blank line final double PARTNER_RATE = 300.00; final double REGULAR_RATE = 150.00; double employeeRate = 0; int employeeCount = 0; double payRate = 0.0; double totalCost = 0.0; double workHours = 0.0; double averageBilling = 0.0; double averageHours = 0.0; String employeeType = "employeeType"; // create a Scanner object named sc Scanner sc = new Scanner(System.in); String choice = "y"; while (!choice.equalsIgnoreCase("n")) { // get the input from the user declaring which consultant and assigns string and rate System.out.print("Is the consultant a partner?: (y/n) "); choice = sc.next(); employeeCount = employeeCount + 1; if (choice.equals("y") || choice.equals("Y")) payRate = PARTNER_RATE; if (choice.equals("y") || choice.equals("Y")) employeeType = "Partner Consultant"; if (choice.equals("n") || choice.equals("N")) payRate = REGULAR_RATE; if (choice.equals("n") || choice.equals("N")) employeeType = "Regular Consultant"; System.out.print("Enter Employee Hours: "); workHours = sc.nextDouble(); System.out.println(); //calculate total cost averageHours = workHours / employeeCount; averageBilling = totalCost / employeeCount; totalCost = (payRate * workHours); NumberFormat currency = NumberFormat.getCurrencyInstance(); System.out.println( "Employee Type: " + employeeType + "\n" + "Employee Hours: " + (workHours) + "\n" + "Total Employee Cost: " + currency.format(totalCost) + "\n"); System.out.println(); // see if the user wants to add another employee System.out.print("Do you want to add another employee? (y/n): "); choice = sc.next(); System.out.println(); } // calculate and display total number of employees, total project cost, avg hours worked, avg billing rate NumberFormat currency = NumberFormat.getCurrencyInstance(); String message = "Total number of Employees: " + employeeCount + "\n" + "Total Project Cost: " + currency.format(totalCost) + "\n" + "Average Hours Worked : " + (averageHours) + "\n" + "Average Billing Rate: " + currency.format(averageBilling) + "\n"; System.out.println(message); } }
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Spurl | quote |
Sponsored Links
REMOVE ADS
Old 07-08-2008, 01:50 PM   #2
shocking4life
whore
 
 
Join Date: Jul 2006
Location: CA
Posts: 220/0.27
Threads: 6
United States MALE
Re: Hey guys looking for some Java help

anyone? The problem seems to be with my variables. I need to have a set of variables that are used for each individual employee, and then a set of overall variables that track all the various totals. But I cant figure out how to set that part up.
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Spurl | quote |
Old 07-12-2008, 02:36 PM   #3
toxicjn
whore
 
 
Join Date: Oct 2004
Location: Minneapolis, MN
Posts: 67/0.05
Threads: 0
MALE
Re: Hey guys looking for some Java help

Ok, I'm a C guy, so correct any syntax errors. I'm sure this is what you ment to do. I created an additional variable called employeeCost which is added to totalCost at the end of each while loop. And I moved averageHours and averageBilling out of the loop.

Like I said, I did not compile this, good luck.


Code:
import java.text.NumberFormat; import java.util.Scanner; public class BillingAppp { public static void main(String[] args) { // welcome the user to the program System.out.println("Weclome to the Billing Application"); System.out.println(); // print a blank line final double PARTNER_RATE = 300.00; final double REGULAR_RATE = 150.00; double employeeRate = 0; int employeeCount = 0; double payRate = 0.0; double employeeCost = 0.0; double totalCost = 0.0; double workHours = 0.0; double averageBilling = 0.0; double averageHours = 0.0; String employeeType = "employeeType"; // create a Scanner object named sc Scanner sc = new Scanner(System.in); String choice = "y"; while (!choice.equalsIgnoreCase("n")) { // get the input from the user declaring which consultant and assigns string and rate System.out.print("Is the consultant a partner?: (y/n) "); choice = sc.next(); employeeCount = employeeCount + 1; if (choice.equalsIgnoreCase("y")) { payRate = PARTNER_RATE; employeeType = "Partner Consultant"; } else if (choice.equalsIgnoreCase("n")) { payRate = REGULAR_RATE; employeeType = "Regular Consultant"; } System.out.print("Enter Employee Hours: "); workHours = sc.nextDouble(); System.out.println(); //calculate the employees cost, and print employeeCost = (payRate * workHours); NumberFormat currency = NumberFormat.getCurrencyInstance(); System.out.println( "Employee Type: " + employeeType + "\n" + "Employee Hours: " + (workHours) + "\n" + "Total Employee Cost: " + currency.format(employeeCost) + "\n"); System.out.println(); totalCost = totalCost + employeeCost; // see if the user wants to add another employee System.out.print("Do you want to add another employee? (y/n): "); choice = sc.next(); System.out.println(); } //end while // calculate and display total number of employees, total project cost, avg hours worked, avg billing rate averageHours = workHours / employeeCount; averageBilling = totalCost / employeeCount; NumberFormat currency = NumberFormat.getCurrencyInstance(); String message = "Total number of Employees: " + employeeCount + "\n" + "Total Project Cost: " + currency.format(totalCost) + "\n" + "Average Hours Worked : " + (averageHours) + "\n" + "Average Billing Rate: " + currency.format(averageBilling) + "\n"; System.out.println(message); } //end main } //end class
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Spurl | quote |
Old 07-15-2008, 01:40 PM   #4
shocking4life
whore
 
 
Join Date: Jul 2006
Location: CA
Posts: 220/0.27
Threads: 6
United States MALE
Re: Hey guys looking for some Java help

toxicjn thanks for your reply, this is exactly what had to be fixed,
i actually did finally figure this with the help of a buddy before i had returned to check this post lol.

but again thanks!
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Spurl | quote |
Reply

WR > Community > Computers and Programming
Reload this Page Hey guys looking for some Java help
Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:

Powered by Waldo 12345678910 1213 14 15 Copyright © 2000-2005 Jelsoft Enterprises Limited.
Page generated in 1.17211103 seconds (95.52% PHP - 4.48% MySQL) with 11 queries
206.212.255.30 Message Boards and Forums Directory