|
Beginner; Create a class to store info and constructor to initialize
Hey everyone. I love that this forum exists and we can learn from one another. At this point I am the one doing all of the learning, but I will someday be able to return the favor for other beginners.
I need a little help. My time, of late, is very limited for my studying of Java and I am saddened by this because I am interested in learning more. I have a project I need to submit for school and I thought I could enlist some help in gaining understanding of how to do it.
I have a payroll program:
import java.util.Scanner;
public class Payroll3
{
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
boolean enterMoreData = true;
while(enterMoreData)
{
System.out.print ( "Enter employee name: " );
String theName = input.nextLine();
if(theName.equalsIgnoreCase("stop"))
{
input.close();
break;
}
int hoursWorked;
do
{
System.out.println("Enter hours worked: ");
String line = input.nextLine();
hoursWorked = Integer.parseInt(line);
if(hoursWorked < 0)
System.out.println("number must be positive");
}
while(hoursWorked < 0);
int hourlyPayRate;
do
{
System.out.println("Enter hourly pay rate: ");
String line = input.nextLine();
hourlyPayRate = Integer.parseInt(line);
if(hourlyPayRate < 0)
System.out.println("number must be positive");
}
while(hourlyPayRate < 0);
// multiply hours worked * hourly pay rate
int weeklyPay = hoursWorked * hourlyPayRate;
// display employee name and weekly pay total
System.out.printf( "Employee Name: %s, Weekly pay is $%d%n",
theName, weeklyPay );
}
}
}
I got help from some of you to get this far and I learned a lot. Thanks to those who helped. Now I need to modify the program for these requirements:
Modify the Payroll 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.
I am unsure of how to put a class in that will store this info until called upon by the constructor. I will be doing some reading this afternoon trying to find this in my text, I am not just being lazy. I would, though appreciate any help and explanations that you may offer. I really do appreciate this.
Badness
|