Results 1 to 3 of 3
Thread: Help with program class?
- 11-22-2009, 02:58 AM #1
Member
- Join Date
- Oct 2009
- Posts
- 20
- Rep Power
- 0
Help with program class?
Create a class named Eggs. Its main() method holds an integer variable named eggs to which you will assign a value entered by a user at the keyboard. Create a method to which you pass eggs. The method displays the eggs in dozens; for example, 50 eggs is 4 full dozen(with 2 eggs remaining).
Am I close with this? Can you point me in the right direction please?
//Import necessary packages
import java.util.Scanner;
public class Eggs
{
public static void main (String args[])
{
//Declare variables
int eggs;
Scanner input = new Scanner(System.in);
//Get user input
System.out.print("How many eggs do you have? ");
eggs = input.nextInt();
int full = eggs/12;
remaining = eggs%12;
}
public class calculateEggs(int eggs);
{
System.out.print("You have " + full + "eggs" + "with" + remaining + "eggs remaining");
}
}
- 11-22-2009, 03:46 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Does that compile? If not and you cannot understand the compiler message, post it and maybe someone can explain it.
Read the question closely. You are asked to "Create a method to which you pass eggs" you weren't asked to create any more classes. So
should probably beJava Code:public class calculateEggs(int eggs); { System.out.print(" // etc
Java Code:static void displayCount(int eggs) { System.out.print(" // etc
- 11-22-2009, 10:10 AM #3
Member
- Join Date
- Feb 2008
- Posts
- 78
- Rep Power
- 0
Hi,
That program will not compile. When you attempt to run it you will get a compilation error message:
Java Code:'{' expectedAs someone has already mentioned, the line of code 'public class calculateEggs(int eggs);' is not necessary. When you comment that line out and run your code again, you get another error message 'cannot find symbol - variable remaining'. Which means you do not really need to create another class for calculateEggs();Java Code://Import necessary packages import java.util.Scanner; public class Eggs { public static void main (String args[]) { //Declare variables int eggs; Scanner input = new Scanner(System.in); //Get user input System.out.print("How many eggs do you have? "); eggs = input.nextInt(); int full = eggs/12; remaining = eggs%12; } public class calculateEggs(int eggs); { System.out.print("You have " + full + "eggs" + "with" + remaining + "eggs remaining"); } }
I think a bit of modification to you code will do the task.
Similar Threads
-
"Could not find the main class: comparisonDemo.class. Program will exit."
By ziisrick in forum New To JavaReplies: 6Last Post: 05-18-2010, 05:11 PM -
Could not find the main class, program will exit.
By aryubi in forum New To JavaReplies: 39Last Post: 02-19-2010, 10:02 AM -
Can we have a java program without any public class?
By kthaker in forum New To JavaReplies: 3Last Post: 10-06-2009, 08:14 PM -
I am using Jdk1.3. I am not able to import Scanneer class in my program.
By tabrez_k81 in forum New To JavaReplies: 4Last Post: 12-29-2008, 02:20 PM -
clock class program
By jvasilj1 in forum New To JavaReplies: 12Last Post: 02-01-2008, 08:27 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks