943,986 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 2127
  • Java RSS
Sep 21st, 2007
0

Need help understanding how to use Java for a class.

Expand Post »
• 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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
amylaney is offline Offline
3 posts
since Sep 2007
Sep 22nd, 2007
0

Re: Need help understanding how to use Java for a class.

So what's ur exact problem? Displaying the result, or reading from commandline or what?
Reputation Points: 16
Solved Threads: 11
Junior Poster in Training
lookof2day is offline Offline
83 posts
since Aug 2007
Sep 22nd, 2007
0

Re: Need help understanding how to use Java for a class.

Click to Expand / Collapse  Quote originally posted by lookof2day ...
So what's ur exact problem? Displaying the result, or reading from commandline or what?
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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
amylaney is offline Offline
3 posts
since Sep 2007
Sep 23rd, 2007
0

Re: Need help understanding how to use Java for a class.

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.
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Nov 2nd, 2007
0

Re: Need help understanding how to use Java for a class.

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
Last edited by ukankissthis; Nov 2nd, 2007 at 11:19 pm. Reason: forgot to post what I had originally
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ukankissthis is offline Offline
4 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Sum of Vectors
Next Thread in Java Forum Timeline: Help!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC