5 Replies - 438 Views - Last Post: 13 October 2012 - 05:00 PM Rate Topic: -----

#1 jmart  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 29-September 12

Can't get this to run

Posted 13 October 2012 - 03:11 PM

I got it to compile and now I get No main methods, applets, or MIDlets found in file. I know that is because there is no main, but when I do put a main, I get so many errors. Arggggg. Any help here to get this to run???
import java.util.Scanner;

public class payRoll
{
	
	public static boolean status(boolean status)
	{
	int payRate;
	int hoursWorked;
	Scanner keyboard = new Scanner(System.in);
	
		
			do
			{
			System.out.println("Enter the hourly pay rate");
			payRate = keyboard.nextInt();
			}
			while (payRate>7.5 && payRate<18.25);
			if(payRate>7.5 && payRate<18.25)
				status = true;
			else
				status = false;
				System.out.println("You have entered an invalid number");

				do
				{
				System.out.println("Enter the number of hours worked");
				hoursWorked = keyboard.nextInt();
				}
				while  (hoursWorked>0 && hoursWorked<40);
				if(hoursWorked>0 && hoursWorked<40)
					status = true;
				else
					status = false;
					System.out.println("You have entered an invalid number");
					return status;
			
			
		
		
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Can't get this to run

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Can't get this to run

Posted 13 October 2012 - 03:26 PM

You need a main method to run your application, so why dont you put it in and then post the stack trace of the errors.
Was This Post Helpful? 0
  • +
  • -

#3 Kakerergodt  Icon User is offline

  • D.I.C Head

Reputation: 87
  • View blog
  • Posts: 201
  • Joined: 01-May 12

Re: Can't get this to run

Posted 13 October 2012 - 03:27 PM

Compiles and runs fine here, make sure you have it saved in a file called "payRoll.java".
Was This Post Helpful? 0
  • +
  • -

#4 jmart  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 29-September 12

Re: Can't get this to run

Posted 13 October 2012 - 04:23 PM

okay so this is the updated code....still not sure...
import java.util.Scanner;

public class payRoll
{
	public static void main(String[] args)
	{
	int payRate;
	int hoursWorked;
	int status;
	Scanner keyboard = new Scanner(System.in);
	}
		public static boolean status(boolean status)
		{
			do
			{
			System.out.println("Enter the hourly pay rate");
			payRate = keyboard.nextInt();
			}
			while (payRate>7.5 && payRate<18.25);
			if(payRate>7.5 && payRate<18.25)
				status = true;
			else
				status = false;
				System.out.println("You have entered an invalid number");

				do
				{
				System.out.println("Enter the number of hours worked");
				hoursWorked = keyboard.nextInt();
				}
				while  (hoursWorked>0 && hoursWorked<40);
				if(hoursWorked>0 && hoursWorked<40)
					status = true;
				else
					status = false;
					System.out.println("You have entered an invalid number");
					return status;
		}
}


Was This Post Helpful? 0
  • +
  • -

#5 jmart  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 29-September 12

Re: Can't get this to run

Posted 13 October 2012 - 04:36 PM

forgot the errors:
payRoll.java:17: error: cannot find symbol
			payRate = keyboard.nextInt();
			^
  symbol:   variable payRate
  location: class payRoll
payRoll.java:17: error: cannot find symbol
			payRate = keyboard.nextInt();
			          ^
  symbol:   variable keyboard
  location: class payRoll
payRoll.java:19: error: cannot find symbol
			while (payRate>7.5 && payRate<18.25);
			       ^
  symbol:   variable payRate
  location: class payRoll
payRoll.java:19: error: cannot find symbol
			while (payRate>7.5 && payRate<18.25);
			                      ^
  symbol:   variable payRate
  location: class payRoll
payRoll.java:20: error: cannot find symbol
			if(payRate>7.5 && payRate<18.25)
			   ^
  symbol:   variable payRate
  location: class payRoll
payRoll.java:20: error: cannot find symbol
			if(payRate>7.5 && payRate<18.25)
			                  ^
  symbol:   variable payRate
  location: class payRoll
payRoll.java:29: error: cannot find symbol
				hoursWorked = keyboard.nextInt();
				^
  symbol:   variable hoursWorked
  location: class payRoll
payRoll.java:29: error: cannot find symbol
				hoursWorked = keyboard.nextInt();
				              ^
  symbol:   variable keyboard
  location: class payRoll
payRoll.java:31: error: cannot find symbol
				while  (hoursWorked>0 && hoursWorked<40);
				        ^
  symbol:   variable hoursWorked
  location: class payRoll
payRoll.java:31: error: cannot find symbol
				while  (hoursWorked>0 && hoursWorked<40);
				                         ^
  symbol:   variable hoursWorked
  location: class payRoll
payRoll.java:32: error: cannot find symbol
				if(hoursWorked>0 && hoursWorked<40)
				   ^
  symbol:   variable hoursWorked
  location: class payRoll
payRoll.java:32: error: cannot find symbol
				if(hoursWorked>0 && hoursWorked<40)
				                    ^
  symbol:   variable hoursWorked
  location: class payRoll
12 errors


This post has been edited by jmart: 13 October 2012 - 04:36 PM

Was This Post Helpful? 0
  • +
  • -

#6 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Can't get this to run

Posted 13 October 2012 - 05:00 PM

Your variables are out of scope as indicated by cannot find symbol. So although you have declared the variables in the main method, the status method doesnt know about them. So you can either make the class variables and place them outside of your main, or you can declare them in your status method, or you can pass them to the method. In your main method, you also need to call your status method and pass it the required variable.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1