Im looking for some guidance as to how i would go about moving implemenation out of main(String[ ] args). I have tried to do this a few times and all i seem to do is mess up my code.
In the midst of writing the code for my java program, i have seem to taken a misturn somewhere. Any advise or sugestions on what i can do to correct this is much needed. It works good until i get to the employee class near the bottom.
import java.util.Scanner; // This program uses class Scanner
public class Payroll {
public Payroll() {
//create a scanner object to obtain input from command window Scanner input = new Scanner(System.in);
// loop until the user enters 'stop' as the name of the employee. do {
// Get Employee Name System.out.print("Enter Name of Employee:"); employeeName = input.next(); // if the employee name is 'stop', then exit the loop. if (employeeName.equals("stop")) { break;
}
// ask for hourly wage System.out.print("Enter hourly Wage:"); hourlyWage = input.nextDouble(); // require that the hourly wage is a non-negative while (hourlyWage < 0.0) { System.out.print("Hourly wage must be a positive number. Please enter a positive hourly wage:");//prompt hourlyWage = input.nextDouble(); input.nextLine();
}
// ask the hours worked System.out.print("Enter hours worked:"); hoursWorked = input.nextDouble(); // require that hours worked be a non-negative number while (hoursWorked < 0.0) { System.out.print("Hours worked must be a positive number. Please enter a positive number of hours:");//prompt hoursWorked=input.nextDouble();
input.nextLine(); }
weeklyPay = hourlyWage * hoursWorked; System.out.printf("The employee, %s, was paid $ %.2f this week.\n\n", employeeName, weeklyPay);
} while (true);
} } public static void main(String args[]) { new Payroll();
} //end method main
//end class Payroll
public class Employee {
public Employee() {
String name; int hoursworked; int hourlywage; int weeklyPay;
public Employee(String name, int hours, int rate) { this.name = name; this.hoursworked = hours; hourlywage = rate; computeWeeklyPay(); }
If you dont mind can you explain this a lil further im very new to this and atm this one project has me pulling out
import java.util.Scanner;
public class Payroll {
public Payroll() {
{ // create Scanner to obtain input from command window Scanner input = new Scanner( System.in );
// prompt for and input employee name System.out.println( "Please enter the employee name:" ); String employeeName = input.nextLine(); // read a line of text System.out.println(); // outputs a blank line
// prompt for and input employee hourly wage System.out.println( "Please enter the employee hourly wage:" ); double hourlyWage = input.nextDouble(); // read a line of text System.out.println(); // outputs a blank line
// prompt for and input employee hours worked System.out.println( "Please enter the employee hours worked:" ); double hoursWorked = input.nextDouble(); // read a line of text System.out.println(); // outputs a blank line
I seem to be getting this error message now after i figured out why it wasnt running.Any ideas or suggestions on how to correct this?
C:\jdk1.5.0_14\bin>javac Payroll.java Payroll.java:51: illegal start of expression public void static main(String[] args) {} ^ 1 error
import java.util.Scanner;
public class Payroll {
public Payroll() {
{ // create Scanner to obtain input from command window Scanner input = new Scanner( System.in );
// prompt for and input employee name System.out.println( "Please enter the employee name:" ); String employeeName = input.nextLine(); // read a line of text System.out.println(); // outputs a blank line
// prompt for and input employee hourly wage System.out.println( "Please enter the employee hourly wage:" ); double hourlyWage = input.nextDouble(); // read a line of text System.out.println(); // outputs a blank line
// prompt for and input employee hours worked System.out.println( "Please enter the employee hours worked:" ); double hoursWorked = input.nextDouble(); // read a line of text System.out.println(); // outputs a blank line
my assignment called for me to Move implemenation out of main(String[ ] args). I thought this was what i was doing but it isnt i guess. Do you know where i might could look for information or ideas on how to accomplish this and my code still runs.
Thank you all for the much needed help. I read more on how packages from both sites that was listed by you guys.So now my error is gone Yay but my program fails to run even though it gives no errors.Any suggestions on why this might be happening?
I have been working on trying to get a project to run for 2 days but i receive the following error.Let me backup a lil. This is what my code looks like. I had no errors until my assignment called for me to Move implemenation out of main(String[ ] args). Any help or suggestions will be much appreciated.
package payroll;
import java.util.Scanner;
public class Payroll {
{ // create Scanner to obtain input from command window Scanner input = new Scanner( System.in );
// prompt for and input employee name System.out.println( "Please enter the employee name:" ); String employeeName = input.nextLine(); // read a line of text System.out.println(); // outputs a blank line
// prompt for and input employee hourly wage System.out.println( "Please enter the employee hourly wage:" ); double hourlyWage = input.nextDouble(); // read a line of text System.out.println(); // outputs a blank line
// prompt for and input employee hours worked System.out.println( "Please enter the employee hours worked:" ); double hoursWorked = input.nextDouble(); // read a line of text System.out.println(); // outputs a blank line
// main method begins execution of Java Application } public static void main(String args[]) {
} // end method main
} // end class Payroll
Error
C:\jdk1.5.0_14\bin>java Payroll Exception in thread "main" java.lang.NoClassDefFoundError: Payroll (wrong name: payroll/Payroll) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:620) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:1 4) at java.net.URLClassLoader.defineClass(URLClassLoader.java:260) at java.net.URLClassLoader.access$100(URLClassLoader.java:56) at java.net.URLClassLoader$1.run(URLClassLoader.java:195) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
HERE IS THE CODE C:\jdk1.5.0_14\bin>javac InventoryProgram.java InventoryProgram.java:10: ';' expected ^ 1 error
public class InventoryProgram{
public static void main(String[] args)
public String name; public int itemNumber; public int stockQuantity; public double price; public InventoryProgram(String name, int itemNumber, int stockQuantity, double price){ this.name = name; this.itemNumber = itemNumber; this.stockQuantity = stockQuantity; this.price = price; }
I tryed adding one and still somehow manage to get that error.. So i must be having a lack of brain function moment.. Any help with this will be much appreciated