• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

fast enough

 
kofi ofei
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the programme below doesnt compile. i was wondering if i could get some assistance in solving this problem. thanks



public class FastEnough{
int speed, memory;
public static void main(String[] args) {
FastEnough myComputer = new FastEnough();
myComputer.speed = 150;
myComputer.checkSpeed();
myComputer.memory = 16;
myComputer.checkMemoryAndSpeed();
}
public void checkSpeed(){
if(speed < 200) System.out.println(speed + "MHz is too slow");
else if(speed < 300)System.out.println(speed + "MHz is fast enough");
else if(speed < 400)System.out.println(speed + "MHz is very fast");
else if(speed <=450)System.out.println(speed + "MHz is the fast");
else System.out.println("Does your PC really run at"+ speed + "MHz?");
}






public void checkMemoryAndSpeed(){
if((speed< 200)|| (memory<32))System.out.println("Upgrade");
}
}
public void checkMemory(){
String m;
if(memory == 16)m = "far too little";
else if(memory == 32)m = "just enough";
else m = "ample memory";
System.out.println(memory + " MB is "+ m);
}
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java In General (Beginner) forum.

Mark
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the compiler error tell you? Something cryptic about it expects something other than what it found? I'm guessing the text of the message is confusing (if I spotted the right problem it's one of the less helpful messagse around) but the line number points at or right after the problem.
 
kofi ofei
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class or inferface expected line 21
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so look at line 21. Then look right before line 21.

Hint: use a programmer's editor that indents your code, and balances parentheses and braces for you. They make this sort of error much easier to find (and prevent them from happening in the first place.)
 
Ryan McGuire
Ranch Hand
Posts: 1048
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're going to mention line numbers, may I suggest that you point out which line in your source code is the line in question? AT THE VERY LEAST don't add blank lines when you copy the source code into your message.

If line 1 is "public class FastEnough{", line 21 is one of the blank lines. But if all the blank lines are removed, line 21 is "public void checkMemory(){". Is that line 21 in the source code you're compiling?

The error message means that the compiler has reached the end of one class/interface definition in a file and is expecting the start of a second one. Can you think of why compiler might think it has already reached the end of your class when it gets to the start of the checkMemory() method?

Ryan
[ May 23, 2005: Message edited by: Ryan McGuire ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic