| | |
Store and Retrieve Information
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jun 2007
Posts: 5
Reputation:
Solved Threads: 0
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
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
");//promptnumber1 = 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
•
•
•
•
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
Java Syntax (Toggle Plain Text)
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).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 = ""; while(nameOfEmployee.equals("")){ nameOfEmployee = input.nextLine(); } }//end while System.out.println("Ending program"); }//end method main }//end class PayrollProgram
![]() |
Similar Threads
- Retrieve Information from Database & Display into ASP.NET Web Controls Textbox (ASP.NET)
- Retrieve information (MS SQL)
- access database search and display (Visual Basic 4 / 5 / 6)
- Sorting from a file (C)
- Unable to retrieve data (Windows NT / 2000 / XP)
- Retrieving Information (Storage)
- Perl/CGI (Saving Data) Part III (Computer Science)
Other Threads in the Java Forum
- Previous Thread: Help is needed for newbie in class!!
- Next Thread: Function Arguments
Views: 3502 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
6 android api apple applet application arc arguments array arrays automation binary bluetooth bold c++ chat class classes client code compare component coordinates database datagram doctype draw eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework html ide ideas image ingres input integer internet intersect ip j2me java javaexcel javaprojects jmf jni jpanel jtextarea julia linux list loop map method methods mobile netbeans newbie nextline number object oracle print problem program programming project recursion recursive scanner screen sell server set size sms socket sort sql string swing test threads time transfer tree user websites windows





