Store and Retrieve Information

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2007
Posts: 5
Reputation: 4zlimit is an unknown quantity at this point 
Solved Threads: 0
4zlimit 4zlimit is offline Offline
Newbie Poster

Store and Retrieve Information

 
0
  #1
Jun 6th, 2007
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:

1. I believe I need to create the class, EmployeeData (?).
2. I need to store employee info, rate, and hours worked.
3. 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
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Store and Retrieve Information

 
0
  #2
Jun 6th, 2007
Originally Posted by 4zlimit View Post
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:

1. I believe I need to create the class, EmployeeData (?).
2. I need to store employee info, rate, and hours worked.
3. 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
well... you still have some errors in your code. Just try the one I've posted under here, and try and find the differences with your code. Maybe it 'll help you understand where your code went wrong

  1. import java.util.Scanner; // program uses class Scanner
  2.  
  3. /** Creates a new instance of PayrollProgram */
  4. public class PayRollProgram
  5. {
  6.  
  7. //main method begins execution of Payroll Program java application
  8. public static void main (String[]args)
  9. {
  10. // create Scanner to obtain input from command window
  11. Scanner input = new Scanner( System.in );
  12.  
  13. int number1; // hourly rate
  14. int number2; // hours
  15. int product; // product of number1 and number2
  16.  
  17.  
  18. System.out.println("Please enter your name or stop to quit the program:");//prompt
  19. String nameOfEmployee=input.nextLine();
  20.  
  21. while(!(nameOfEmployee).equalsIgnoreCase("stop"))
  22.  
  23. {
  24.  
  25. System.out.println("Enter hourly rate");//prompt
  26. number1 = input.nextInt(); // read first number
  27. while (number1 <=0)//prompt until user enters positive value
  28. {
  29. System.out.println ("Hourly rate must be positive. Please enter hourly rate again");//prompt user to enter in hourly rate again
  30. number1 = input.nextInt(); // read first number
  31. }
  32. System.out.println( "Enter hours: " ); // prompt
  33. number2 = input.nextInt();//read second number
  34. while (number2 <=0)//prompt until user enters positive value
  35. {
  36. System.out.println ("Hours must be positive. Please enter hours worked again");//prompt user to enter in hours worked again
  37. number2 = input.nextInt();//read second number
  38.  
  39. }
  40.  
  41. product = number1 * number2; // multiply numbers
  42. System.out.print( nameOfEmployee ); // display employee name
  43. System.out.printf("'s weekly pay is $%d\n",product);
  44.  
  45. System.out.println("Please enter your name or stop to quit the program:");//prompt
  46. nameOfEmployee = "";
  47. while(nameOfEmployee.equals("")){
  48. nameOfEmployee = input.nextLine();
  49. }
  50.  
  51. }//end while
  52. System.out.println("Ending program");
  53.  
  54. }//end method main
  55.  
  56. }//end class PayrollProgram
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 3502 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC