Results 1 to 6 of 6
Thread: Java Programming in Netbeans
- 11-03-2008, 03:44 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 2
- Rep Power
- 0
Java Programming in Netbeans
import java.util.Scanner; // program uses class Scanner
public class NewClass5 {
/**
* @param args the command line arguments
*/
// main method begins execution of java application
public static void main( String args[] )
{
System.out.println( "Welcome to the Payroll Program " );
boolean stop = false; // This flag will control whether we exit the loop
// Loop until user types "stop" as the employee name:
while (!stop)
{
// create scanner to obtain input from command window
Scanner input = new Scanner ( System.in );
System.out.println(); // outputs a blank line
System.out.print( "Please enter the employee name or stop to end program: " );
// prompt for and input employee name
String empName = input.nextLine(); // read employee name
if ( empName.equals("stop")) // Check whether user indicated to stop program
{
stop = true;
}
else
{
// User did not indicate to stop, so continue reading info for this iteration:
float hourlyRate; // hourly rate
float hoursWorked; // hours worked
float weeklyPay; // Weekly Pay for employee
System.out.print( "Enter hourly rate: " ); // prompt for hourly rate
hourlyRate = input.nextFloat(); // read hourly rate
while (hourlyRate <= 0) // prompt until a positive value is entered
{
System.out.print( "Hourly rate must be a positive value. " +
"Please enter the hourly rate again: " ); // prompt for positive value for hourly rate
hourlyRate = input.nextFloat(); // read hourly rate again
}
System.out.print( "Enter hours worked: " ); // prompt for # of hours
hoursWorked = input.nextFloat(); // read # of hours
while (hoursWorked <= 0) // prompt until a positive value is entered
{
System.out.print( "Hours worked must be a positive value. " +
"Please enter the hours worked again: " ); // prompt for positive value for hours worked
hoursWorked = input.nextFloat(); // read hours worked again
}
// Move on to calculate Weekly Pay.
weeklyPay = (float) hourlyRate * hoursWorked; // multiply the hourly rate by the hours worked
// Display output
System.out.println(); // outputs a blank line
System.out.print( empName ); // display employee name
System.out.printf( "'s weekly pay is: $%,.2f\n", weeklyPay); // display weekly pay
System.out.println(); // outputs a blank line
}
}
// Display ending message:
System.out.println( "Program ended" );
System.out.println(); // outputs a blank line
} // end method main
} // end class Payroll1
Above is my payroll program and works to this point. My next step is
create a class to store and retrieve the information within the program.
I am lost and could use some pointers without actually doing the work.
- 11-03-2008, 04:23 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Are you worrying about that how to create a class in NetBeans? Can you explain your question much clearly.
- 11-03-2008, 06:45 AM #3
Member
- Join Date
- Nov 2008
- Posts
- 2
- Rep Power
- 0
I need to modify the Payroll Program so that it uses a class to store and retrieve the employee's
name, the hourly rate, and the number of hours worked. then I need to use a constructor to initialize the
employee information, and a method within that class to calculate the weekly pay.
- 11-03-2008, 07:25 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
So where are you stuck with? Are you asking to write this code. First of all you have to make an attempt first. Then ask questions here lol. Start work on step-by-step.
- 11-04-2008, 07:36 PM #5
Member
- Join Date
- Oct 2008
- Location
- Aberystwyth
- Posts
- 55
- Rep Power
- 0
If you get stuck try breaking your code up into smaller segments. It is an OO Language. lol.
- 11-05-2008, 03:21 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you are familiar with OO concepts it's easy to work on. Most important thing is you should have a clever design for the application looking to build
Similar Threads
-
Java Programming Tutorial
By levent in forum Java TutorialReplies: 1Last Post: 07-04-2008, 08:15 AM -
Java networking programming (II)
By Java Tutorial in forum Java TutorialReplies: 0Last Post: 12-27-2007, 06:19 PM -
Java networking programming (I)
By Java Tutorial in forum Java TutorialReplies: 0Last Post: 12-24-2007, 07:21 PM -
Java Applet 3D programming
By ramk in forum Java AppletsReplies: 0Last Post: 11-28-2007, 10:36 PM -
Java Programming
By JavaForums in forum Java TutorialReplies: 0Last Post: 07-28-2007, 11:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks