File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes fast enough Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "fast enough" Watch "fast enough" New topic
Author

fast enough

kofi ofei
Ranch Hand

Joined: May 22, 2005
Posts: 39
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

Joined: Feb 05, 2001
Posts: 17260
    
    6

Moving to Java In General (Beginner) forum.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
kofi ofei
Ranch Hand

Joined: May 22, 2005
Posts: 39
class or inferface expected line 21
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.)


[Jess in Action][AskingGoodQuestions]
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1013
    
    3
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
 
subject: fast enough