Question:
Modifying a java program..please help!?
anonymous
2008-06-27 23:16:57 UTC
I have to write a Java program for an assignment. It’s a payroll program. The first part I had to create a non-GUI based Java application that calculates weekly pay for an employee. The application should display text that requests the user input the name of the employee, the hourly rate, and the number of hours worked for that week. The application should then print out the name of the employee and the weekly pay amount. In the printout, display the dollar symbol ($) to the left of the weekly pay amount and format the weekly pay amount to display currency.
The next step I had to do was modify the payroll program application so it continues to request employee information until the user enters stop as the employee name. In addition, program the application to check that the hourly rate and number of hours worked are positive numbers. If either the hourly rate or the number of hours worked is not a positive value, the application should prompt the user to enter a positive amount.

My program and what my instructor said are below:

public class Payroll{
* myname
* 06/20/08
* payroll/calculation

System.out.print("Enter employee name: ");

employee = Input.readString();
while (employee.equals(""))
{
System.out.print("Enter proper employee name: ");
employee = Input.readString();
continue;
}

// hours worked
while (!hours_valid)
{
System.out.print("How many hours did " + employee + " work? ");
hours = Input.readDouble();
while (hours < 0)
{
System.out.print("Enter proper number of hours: ");
hours = Input.readDouble();
continue;
}
hours_valid = true;

}

// rate
while (!rate_valid)
{
System.out.print("How much does " + employee + " make per hour? ");
rate = Input.readDouble();
while (rate < 0)
{
System.out.print("Enter proper number for rate: ");
rate = Input.readDouble();
continue;
}
rate_valid = true;

}

// compute pay check
double pay = rate * hours;
NumberFormat fmt = NumberFormat.getCurrencyInstance();
System.out.println("\n" + employee + " worked for " + hours
+ " hours at " + fmt.format(rate) + "/hr; paycheck = "
+ fmt.format(pay));
}

}



Instructor comments:
You still need to cover some of the basics – IE: importing classes, the main method. This was a 50 point assignment. Here is what I got so you can see where I made my mistakes and help me change this.
The application compiles and runs 6/10
The application properly employs the use of a loop to request multiple employee info 5/20

Now I have to modify the program so that it uses a class to store and retrieve the employee’s name, the hourly rate, and the number of hours worked. Use a constructor to initialize the employee information, and a method within that class to calculate the weekly pay. Once stop is entered as the employee name, the application should terminate. Make sure the program maintains all the functionality required in previous assignments and your source code is readable and well documented.

Please help!

Thank you for your time!
Three answers:
Neeraj Yadav♥
2008-06-29 07:19:12 UTC
Lol ..again!



Ok,i will give you basic idea about what that code would be



Use collection (e.g ArrayList/Map or so)To store the employee data.

where you can simply add(data); later make logic as

if(employee==stop)

{

System.exit();

}



this will resolve your problem

Good Luck!
anonymous
2016-04-06 07:05:28 UTC
Just add an overloaded constructor: public Account (String owner, long account) { name = owner; acctNumber = account; balance = 0.0; } To demonstrate that this works, you can remove the third parameter from the existing test cases, like this: Account acct1 = new Account ("Ted Murphy", 72354); The account will still have a starting balance of 0.0. Actually, this is true even if we didn't explicitly set it to 0.0 in our new constructor because of the way Java initializes variables, but it still illustrates the point.
black heart
2008-06-28 02:35:39 UTC
Please end your email to add me on your messenger to answer on line

.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...