Results 1 to 7 of 7
  1. #1
    arrech326 is offline Member
    Join Date
    Nov 2009
    Posts
    13
    Rep Power
    0

    Post Program Error Help!!!

    :confused:
    Java Code:
    // Program: Payroll Program Part 2
    // File:	Payroll.java
    // Summary: Payroll Calculator that interacts with user to calculate the employee's payroll with the hourly rate and hours worked by the employee.
    // Author:	Charlene Arreche
    // Date:	October 30,2009.
    
    import java.util.Scanner;//This line allows the user to interact with the application.
    import java.text.NumberFormat;//This line is used by the application as instructions to format currency.
    
    public class Payroll{//Payroll class
    	private String Employee; // This lines declares Employee as character variable in the application.
    	private Double Rate,Hours,Salary; // This lines declares Payroll, Rate and Hours as numeric variables in the application.
    
    	
    	public void getEmployee(){		
    		System.out.println("Welcome to the Payroll Calculator Application.");//This line welcomes the user to the application.
    		System.out.println("Please enter the employee's name here.");//This line prompts the user to input the employee's name.
    		System.out.println("To quit the application enter stop as name."); //This line prompts the user to enter the word stop to quit the application
    		if (Employee.equalsIgnoreCase("stop"));
    		 System.out.println("Good bye!");
    	}//Ends getEmployee module
    	public void getRate(){
    		System.out.println("Please enter the hourly rate for " + Employee);// This line prompts the user to input the hourly rate for that employee.
    		if (Rate >0);
    		System.out.println("Please enter a possitive amount.");//Prompts the user to enter a positive amount
    }//Ends getRate module
    	public void getHours(){
    		System.out.println("Please enter how many hours " + Employee + " worked this week");// This line prompts the user to input the hours worked by that employee.
    		if (Hours > 0);
    		System.out.println("Please enter a positive amount.");
    	}//Ends getHours module
    	public void Calculation(){	
    		 Salary = Rate * Hours;// This is the calculation the program needs to do to get the total amount.
    			System.out.print("The payroll for " + Employee + " is " + nf.format (Salary) + ". ");
    			System.out.print(Employee + " worked " + Hours + " hours with an hourly rate of " + nf.format (Rate)+ ".");
    				//These lines output the user the Employee's name, the total payroll for that week,
    				// the hours worked and the hourly rate for that employee.
    	
    		userInput.close();	
    	}//End main method
    }//End class
    Java Code:
    import java.text.NumberFormat;
    import java.util.Scanner;
    
    // Program: Payroll Program Part 2
    // File:	ProgramPayroll.java
    // Summary: Payroll Calculator that interacts with user to calculate the employee's payroll with the hourly rate and hours worked by the employee.
    // Author:	Charlene Arreche
    // Date:	November 7,2009.
    
    public class ProgramPayroll {
    	
    	public static void main(String args[]){			
    		Scanner userInput = new Scanner(System.in);//This line tells the application expects input from the user.
    		NumberFormat nf = NumberFormat.getCurrencyInstance();//This line is used to format currency.		
    		ProgramPayroll payrollPro = new ProgramPayroll();//Creates object payrollPro
    			payrollPro.getEmployee();
    	}
    }// Ends class
    When I run the program it gives me this error.
    java.lang.NoSuchMethodError: main
    Exception in thread "main"


    What can I do to make it run?? Thanks!!
    -Charlene

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    Make sure you compile and run the ProgramPayroll class because that's the one that has your main method in it.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  3. #3
    arrech326 is offline Member
    Join Date
    Nov 2009
    Posts
    13
    Rep Power
    0

    Default

    I was running both at the same time and gave me that error. when I run PayrollProgram it gives me this error:

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method getEmployee() is undefined for the type ProgramPayroll

    at ProgramPayroll.main(ProgramPayroll.java:16)
    * line 16 in PayrollProgram is payrollPro.getEmployee();

    I dont know how to make both classes talk to eachother. I've tried with objects and still don't get it :(
    -Charlene

  4. #4
    Turtle is offline Member
    Join Date
    Nov 2007
    Location
    New Zealand
    Posts
    36
    Rep Power
    0

    Smile

    This error...

    * line 16 in PayrollProgram is payrollPro.getEmployee();

    is happening because it can not compile the class PayRole.java.

    And it can not compile the class PayRole.java because PayRole.java has errors.

    If you fix PayRole.java you will be able to compile PayrollProgram.

    These errors are caused by trying to call methods on objects that have not been declared inside of PayRole.

    An example such an error is inside of the method Calculation where this code is...

    nf.format (Salary)

    The problem is, inside of Calculation() there is no object called nf. nf is undefined. The next place your program tries to look is in the class, and again there is no nf defined. You may have defined nf in another somewhere else, and if you did it will not be "visible". This type of error is called a scope error. Your object nf is either "undefined" or "out of scope".


    I think you have some serious misunderstandings about how to structure your program. And I will try to help you with these.

    In Object Oriented Programming (java programming) we use classes to group related data and behavior for "something". Beginners find this grouping difficult to grasp. So I will illustrate it with an example.

    Imagine you are trying to create a drawing program. You would want to create a Circle class. This class stores data and behavior related to Circles...

    class Circle {

    private int x, y; // Circle's location
    private int radius; // Circle's radius

    // Constructor for a Circle
    public Circle( int x, int y, int radius ) {
    this.x = x; // Store x
    this.y = y; // Store y
    this.radius = radius; // Store radius
    }

    // Shift a circle by some dx, dy
    public void translate(int dx, int dy) {
    // translate the cirlce by dx, dy
    x = x + dx;
    y = y + dy;
    }
    }

    The data for a circle is: x, y, radius.
    The behavior for a circle is: translate(dx, dy)

    Notice that this class does not contain code related to a specific drawing program.
    Your drawing program will use this class. Your drawing program will have it's own class, and all of the application logic will be placed inside of it.
    If your drawing program needs to translate the circle, then it will call the translate method...

    Cirlce circle = new Circle(5, 5, 10);
    circle.translate(20, 20);

    But all application related code will be placed in your drawing application class.
    For instance, asking the user how big the circle should be and where it is located.

    I hope this helps you to create brilliant applications.

    Best of luck.

  5. #5
    aaroncarpet's Avatar
    aaroncarpet is offline Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    147
    Rep Power
    0

    Default

    make a folder payroll then put your.java files into them the top line of both classes should have this line

    Java Code:
     package payroll;
    it cant find ther other class
    Last edited by aaroncarpet; 11-18-2009 at 07:00 AM. Reason: then compile both classes again and run your entry class that has main

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,178
    Rep Power
    20

    Default

    Ignore the previous two. It's nothing to do with not compiling Payroll, or package structures.
    Your problem is that this code:

    Java Code:
    		ProgramPayroll payrollPro = new ProgramPayroll();//Creates object payrollPro
    			payrollPro.getEmployee();
    is creating a ProgramPayroll object. And that class does not have a getEmployee() method. That method exists in the Payroll class.

    I suspect you actually wanted to do:

    Java Code:
    		Payroll payrollPro = new Payroll();//Creates object payrollPro
    			payrollPro.getEmployee();
    ?
    Maybe?

  7. #7
    Turtle is offline Member
    Join Date
    Nov 2007
    Location
    New Zealand
    Posts
    36
    Rep Power
    0

Similar Threads

  1. error running java program
    By bdasilva in forum New To Java
    Replies: 1
    Last Post: 06-29-2009, 02:46 AM
  2. Same error msg with every program Java Textpad
    By peterdfl in forum New To Java
    Replies: 7
    Last Post: 04-17-2009, 05:49 AM
  3. I can't fix this runtime error in my program
    By Sinnergy in forum New To Java
    Replies: 5
    Last Post: 02-25-2009, 05:29 PM
  4. CRC check program 1 error
    By javakid9000 in forum New To Java
    Replies: 1
    Last Post: 03-19-2008, 06:04 AM
  5. Replies: 1
    Last Post: 08-07-2007, 08:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •