| | |
Need help understanding how to use Java for a class.
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Sep 2007
Posts: 3
Reputation:
Solved Threads: 1
• 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.
•
•
Join Date: Sep 2007
Posts: 3
Reputation:
Solved Threads: 1
I am trying to use JCreator and I do not know exactly what I am supposed to do. I am not going to lie. I am so confussed in this class. I am a dummie to Java. This is my last class for my diploma and I am failing. I am not sure how to complete the code or exactly what code I am supposed to use. I have been searching the web trying to get a better understanding, but it is doing no good. I wish I had someone to help me understand. I have created the workspace for the assignment in JCreator, but I do not know where to go after that.
Before you start thinking in terms of code, maybe try understanding the steps involved in english. Write out some dot points on a piece of paper to get a better idea of what is going on. I'll give you step one:
Display text: "Please enter employee's name." Get input and store it somewhere.
Don't worry about how you are going to do this at this stage, just work out what needs to be done. This is an important stage of the problem solving process called design and it is a stage that requires practice, but I can't stress how important design is in the real world with complex problems to solve.
So give that a go, repost what you think the steps are and let us know what you can / can't code.
Display text: "Please enter employee's name." Get input and store it somewhere.
Don't worry about how you are going to do this at this stage, just work out what needs to be done. This is an important stage of the problem solving process called design and it is a stage that requires practice, but I can't stress how important design is in the real world with complex problems to solve.
So give that a go, repost what you think the steps are and let us know what you can / can't code.
•
•
Join Date: Nov 2007
Posts: 4
Reputation:
Solved Threads: 0
Ok, this is what I have for this program but am getting 3 error messaes first is line 15 it states illegal start of type, the second error is line 84 it states identifier expected and the third line is 88 it states class or interface expected anyone know how to fix this please let me know.
import java.util.Scanner; // program uses Scanner
public class Payroll3
{
private String nameOfEmployee;
public Payroll3( String name )
{
nameOfEmployee = name;
} // end constructor
boolean exit = false; // this flag will stop the program
// loop until user exits from program
while ( !exit )
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
float HoursWorked; // input number of hours worked
float PayRate; // input hourly pay rate
float multiply; // multiply NumberHours with PayRate
// clean input buffer
String cleanInputBuffer = "";
// input the employee's name
System.out.print( "Enter the employee's name or exit to quit:" );
String nameOfEmployee = input.nextLine(); // display employee's name
if(nameOfEmployee.equals("exit"))
{
System.out.println( "End of Program.");
exit = true;
} // end if statement
else
{
// user did not exit, so continue prompt
System.out.print( "Enter number of hours worked:" ); // prompt for input
HoursWorked = input.nextFloat(); // display number of hours worked
while ( HoursWorked <= 0 ) // prompt the user to input a positive number
{
System.out.print( "Number of hours worked must be a positive value." + "Please enter the number of hours worked again:" );
// prompt for a positive number
HoursWorked = input.nextFloat();
} // end while
//set hours worked
public void setHoursWorked( float hours )
{
HoursWorked = HoursWorked;
}
public float getHoursWorked() // method get hours worked
{
return HoursWorked;
}
System.out.print( "Enter hourly pay rate: " ); // prompt for input
PayRate = input.nextFloat(); // display hourly rate
while ( PayRate <= 0 ) // prompt the user to input a positive number
{
System.out.print( "Pay Rate must be a positive value." + "Enter hourly pay rate: " ); // prompt for a positive number
PayRate = input.nextFloat(); // display hourly rate
} // end while
public void setPayRate( float PayRate ) // method set pay rate
{
PayRate = PayRate;
}
public float getPayRate() // method get pay rate
{
return PayRate;
}
public float calculateWeeklyPay()
{
return multiply = HoursWorked * PayRate; //calculate weekly pay
}
System.out.print( "Total weekly pay is $%.2f\n", multiply); // display weekly pay
cleanInputBuffer = input.nextLine();
} // end else statement
System.out.println(); // inserts a blank line
} // end while
} // end main
} // end class Payroll3
and
import java.util.Scanner;
public class TestPayroll3
{ // start Payroll3
public static void main( String args[])
{
Scanner input = new Scanner( System.in );
TestPayroll3 myEmployee = new TestPayroll3();
System.out.printf("Enter the employee's name or exit to quit:");
System.out.print( "Enter hourly pay rate: " );
myEmployee.setpayrate(input.nextDouble());
System.out.print( "Please enter the number of hours worked again:" );
myEmployee.sethoursworked(input.nextDouble());
System.out.printf("Employee earned " + myEmployee.calculateweeklypay() );
} // end main
} // end Payroll3
import java.util.Scanner; // program uses Scanner
public class Payroll3
{
private String nameOfEmployee;
public Payroll3( String name )
{
nameOfEmployee = name;
} // end constructor
boolean exit = false; // this flag will stop the program
// loop until user exits from program
while ( !exit )
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
float HoursWorked; // input number of hours worked
float PayRate; // input hourly pay rate
float multiply; // multiply NumberHours with PayRate
// clean input buffer
String cleanInputBuffer = "";
// input the employee's name
System.out.print( "Enter the employee's name or exit to quit:" );
String nameOfEmployee = input.nextLine(); // display employee's name
if(nameOfEmployee.equals("exit"))
{
System.out.println( "End of Program.");
exit = true;
} // end if statement
else
{
// user did not exit, so continue prompt
System.out.print( "Enter number of hours worked:" ); // prompt for input
HoursWorked = input.nextFloat(); // display number of hours worked
while ( HoursWorked <= 0 ) // prompt the user to input a positive number
{
System.out.print( "Number of hours worked must be a positive value." + "Please enter the number of hours worked again:" );
// prompt for a positive number
HoursWorked = input.nextFloat();
} // end while
//set hours worked
public void setHoursWorked( float hours )
{
HoursWorked = HoursWorked;
}
public float getHoursWorked() // method get hours worked
{
return HoursWorked;
}
System.out.print( "Enter hourly pay rate: " ); // prompt for input
PayRate = input.nextFloat(); // display hourly rate
while ( PayRate <= 0 ) // prompt the user to input a positive number
{
System.out.print( "Pay Rate must be a positive value." + "Enter hourly pay rate: " ); // prompt for a positive number
PayRate = input.nextFloat(); // display hourly rate
} // end while
public void setPayRate( float PayRate ) // method set pay rate
{
PayRate = PayRate;
}
public float getPayRate() // method get pay rate
{
return PayRate;
}
public float calculateWeeklyPay()
{
return multiply = HoursWorked * PayRate; //calculate weekly pay
}
System.out.print( "Total weekly pay is $%.2f\n", multiply); // display weekly pay
cleanInputBuffer = input.nextLine();
} // end else statement
System.out.println(); // inserts a blank line
} // end while
} // end main
} // end class Payroll3
and
import java.util.Scanner;
public class TestPayroll3
{ // start Payroll3
public static void main( String args[])
{
Scanner input = new Scanner( System.in );
TestPayroll3 myEmployee = new TestPayroll3();
System.out.printf("Enter the employee's name or exit to quit:");
System.out.print( "Enter hourly pay rate: " );
myEmployee.setpayrate(input.nextDouble());
System.out.print( "Please enter the number of hours worked again:" );
myEmployee.sethoursworked(input.nextDouble());
System.out.printf("Employee earned " + myEmployee.calculateweeklypay() );
} // end main
} // end Payroll3
Last edited by ukankissthis; Nov 2nd, 2007 at 11:19 pm. Reason: forgot to post what I had originally
![]() |
Similar Threads
- Differences Between Java and C/C++ (C++)
- Java Class Class problem (Java)
- Intro to Java help (Java)
- NewBie to Java needs some Help PLEASE!!! (Java)
- Basic help with Java class (Java)
- Confused writing a Java Class (Java)
- Beginning Programming with Java (Java)
- New to Java (Java)
Other Threads in the Java Forum
- Previous Thread: Sum of Vectors
- Next Thread: Help!!
Views: 1711 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addressbook android api append apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component csv database draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia linked linux list loop map method methods mobile netbeans newbie number object objects oracle oriented panel print printf problem program programming project projects recursion replaydirector reporting researchinmotion return robot rotatetext scanner screen se server set size sms socket sort sql stream string swing test threads time transfer tree ubuntu windows





