I am trying to store information then retrieve it on my program. I know I have to use a class and a constructor. The problem is that my text doesn't have any good examples that I can view. I am truly lost. I am not sure
1. where to build this info
2. how to retrieve it
Here is my best try:
- I believe I need to create the class, EmployeeData (?).
- I need to store employee info, rate, and hours worked.
I believe the class needs to be created between -->>
public class PayrollProgram
{DEFINE CLASS HERE?????
//main method begins execution of Payroll Program java application
public static void main (String[]args)
{
Any pointers/help is truly appreciated.
import java.util.Scanner; // program uses class Scanner
/** Creates a new instance of PayrollProgram */
public class PayrollProgram
{
//main method begins execution of Payroll Program java application
public static void main (String[]args)
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
int number1; // hourly rate
int number2; // hours
int product; // product of number1 and number2
System.out.println("Please enter your name or stop to quit the program:");//prompt
String nameOfEmployee=input.nextLine();
while(!(nameOfEmployee = input.next()).equalsIgnoreCase("stop"))
{
System.out.println("Enter hourly rate:$");//prompt
number1 = input.nextInt(); // read first number
while (number1 <=0)//prompt until user enters positive value
{
System.out.println ("Hourly rate must be positive. Please enter hourly rate again");//prompt user to enter in hourly rate again
number1 = input.nextInt(); // read first number
}
System.out.println( "Enter hours: " ); // prompt
number2 = input.nextInt();//read second number
while (number2 <=0)//prompt until user enters positive value
{
System.out.println ("Hours must be positive. Please enter hours worked again");//prompt user to enter in hours worked again
number2 = input.nextInt();//read second number
}
product = number1 * number2; // multiply numbers
System.out.print( nameOfEmployee ); // display employee name
System.out.printf("'s weekly pay is $%d\n",product);
System.out.println("Please enter your name or stop to quit the program:");//prompt
nameOfEmployee = input.nextLine();
}//end while
System.out.println("Ending program");
}//end method main
}//end class PayrollProgram