| | |
Please check if this compiles in Windows.
![]() |
•
•
Join Date: Mar 2008
Posts: 10
Reputation:
Solved Threads: 0
I am programming using a Java Editor called "TextMate" on the mac and it often gives me errors that I don't get when I compile using TextPad on the Windows machines at school. Can someone check if this compiles on a Windows machine please? The errors are under the code, please tell me if you get the same errors. (Program does not seem to recognize variables stated in the main() method.)
Thanks,
Danny
cannot find symbol
symbol : variable rate
location: class Tuition
rate = 44.5;
^
cannot find symbol
symbol : variable rate
location: class Tuition
rate = 50.00;
^
cannot find symbol
symbol : variable rate
location: class Tuition
return rate;
^
cannot find symbol
symbol : variable tuition
location: class Tuition
tuition = rate * hours;
^
cannot find symbol
symbol : variable hours
location: class Tuition
tuition = rate * hours;
^
cannot find symbol
symbol : variable tuition
location: class Tuition
return tuition;
^
cannot find symbol
symbol : variable fees
location: class Tuition
fees = tuition * 0.08;
^
cannot find symbol
symbol : variable fees
location: class Tuition
return fees;
^
8 errors
Thanks,
Danny
java Syntax (Toggle Plain Text)
import java.io.*; import java.text.DecimalFormat; import java.util.*; public class Tuition { public static void main() { int hours = 0; double fees = 0.0; double rate = 0.0; double tuition = 0.0; displayWelcome(); hours = getHours(); rate = getRate(hours); tuition = calcTuition(hours, rate); fees = calcFees(tuition); displayTotal(tuition + fees); } //end of main() public static void displayWelcome() { System.out.println("Welcome to Dannys Tuition Calculator!"); } //end displayWelcome() public static int getHours() { String strHours; int hours = 0; Scanner scannerIn= new Scanner(System.in); System.out.print("Please enter the total number of hours: "); strHours = scannerIn.next(); hours = Integer.parseInt(strHours); // add try + catch statement return hours; } //end of getHours() public static double getRate(int hours) { if (hours > 15) { rate = 44.5; } else { rate = 50.00; } return rate; } //end of getRate public static double calcTuition(int hour, double rate) { tuition = rate * hours; return tuition; } //end of calcTuition() public static double calcFees(double tuition) { fees = tuition * 0.08; return fees; }//end of calcFees() public static void displayTotal(double total) { DecimalFormat twoDigits = new DecimalFormat("$#,000.00"); System.out.println("The total cost of tuition is: " + twoDigits.format(total) + "."); } //end of displayTotal() } //end of Tuition
cannot find symbol
symbol : variable rate
location: class Tuition
rate = 44.5;
^
cannot find symbol
symbol : variable rate
location: class Tuition
rate = 50.00;
^
cannot find symbol
symbol : variable rate
location: class Tuition
return rate;
^
cannot find symbol
symbol : variable tuition
location: class Tuition
tuition = rate * hours;
^
cannot find symbol
symbol : variable hours
location: class Tuition
tuition = rate * hours;
^
cannot find symbol
symbol : variable tuition
location: class Tuition
return tuition;
^
cannot find symbol
symbol : variable fees
location: class Tuition
fees = tuition * 0.08;
^
cannot find symbol
symbol : variable fees
location: class Tuition
return fees;
^
8 errors
•
•
Join Date: Aug 2008
Posts: 203
Reputation:
Solved Threads: 13
JAVA Syntax (Toggle Plain Text)
public class Tuition { public static void main() { int hours = 0; double fees = 0.0; double rate = 0.0; double tuition = 0.0; displayWelcome(); hours = getHours(); rate = getRate(hours); tuition = calcTuition(hours, rate); fees = calcFees(tuition); displayTotal(tuition + fees); } //end of main()
OK, you need to change it to this:
JAVA Syntax (Toggle Plain Text)
public class Tuition { static int hours = 0; static double fees = 0.0; static double rate = 0.0; static double tuition = 0.0; public static void main() { displayWelcome(); hours = getHours(); rate = getRate(hours); tuition = calcTuition(hours, rate); fees = calcFees(tuition); displayTotal(tuition + fees); } //end of main()
it worked fine for me after changing that.
Last edited by llemes4011; Sep 15th, 2008 at 11:51 pm. Reason: messed up
•
•
Join Date: Mar 2008
Posts: 10
Reputation:
Solved Threads: 0
I keep getting:
Exception in thread "main" java.lang.NoSuchMethodError: main
Program exited with status 1.
Also, I looked up static int and static double and from what I read, I gathered that it initializes the variable to a "default value." Isn't 0 and 0.0 the default value since I stated for it to be so? Static, exactly what is it and how do you know when you need to use it?
Exception in thread "main" java.lang.NoSuchMethodError: main
Program exited with status 1.
Also, I looked up static int and static double and from what I read, I gathered that it initializes the variable to a "default value." Isn't 0 and 0.0 the default value since I stated for it to be so? Static, exactly what is it and how do you know when you need to use it?
Are we talking of Java here ?
Then shouldn't this
Be this:-
For normal Applications Java begins program execution in the Main method takes a String array(which contains the parameters passed to program at the command line) as an argument (and should also be public(since it should be accessible from anywhere), static (As the JVM should be able to call it even before an object of the class is created) and final(we definitely don't want someone overriding our main)), and when you try to run (after compiling) the program, it just can't find a main method which takes a String array as an argument, hence the Exception
Also let us now look at your other errors:-
These variables have been declared inside the main, so it is as good as they do not exist for other methods.
But frankly, you are basically destroying the concept of Object oriented programming in your code. If you go about like this chances are you may learn Java (the syntax) but will not learn how to program in Java. I suggest you go through the Starting Java thread at the start of this forum.
@llemes4011
Do not give people ready to eat food, teach them how to hunt for it.
Then shouldn't this
java Syntax (Toggle Plain Text)
public static void main()
Be this:-
java Syntax (Toggle Plain Text)
public static void main(String[] args)
For normal Applications Java begins program execution in the Main method takes a String array(which contains the parameters passed to program at the command line) as an argument (and should also be public(since it should be accessible from anywhere), static (As the JVM should be able to call it even before an object of the class is created) and final(we definitely don't want someone overriding our main)), and when you try to run (after compiling) the program, it just can't find a main method which takes a String array as an argument, hence the Exception
"main" java.lang.NoSuchMethodError: main is thrown.Also let us now look at your other errors:-
java Syntax (Toggle Plain Text)
int hours = 0; double fees = 0.0; double rate = 0.0; double tuition = 0.0;
But frankly, you are basically destroying the concept of Object oriented programming in your code. If you go about like this chances are you may learn Java (the syntax) but will not learn how to program in Java. I suggest you go through the Starting Java thread at the start of this forum.
@llemes4011
Do not give people ready to eat food, teach them how to hunt for it.
Last edited by stephen84s; Sep 16th, 2008 at 4:16 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
And this
is obviously a lie, as that code is guaranteed to fail to compile on every platform.
•
•
•
•
I am programming using a Java Editor called "TextMate" on the mac and it often gives me errors that I don't get when I compile using TextPad on the Windows machines at school. Can someone check if this compiles on a Windows machine please?
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Mar 2008
Posts: 10
Reputation:
Solved Threads: 0
First of all, thank you all for your help. Program now runs.
Also, I was following a homework assignment in my book step by step as it tells you what to write. A lot of things are very vague when I look them up in my book so thank you for taking the time to explain what you told me to do.
Also, to the guy who said: is obviously a lie, as that code is guaranteed to fail to compile on every platform.
As bizarre as it sounds, it has happened before. Look at my original post, I asked to see if it compiles is all, not for anyone to "do" my homework as you're obviously trying to state.
Thanks again.
Also, I was following a homework assignment in my book step by step as it tells you what to write. A lot of things are very vague when I look them up in my book so thank you for taking the time to explain what you told me to do.
Also, to the guy who said: is obviously a lie, as that code is guaranteed to fail to compile on every platform.
As bizarre as it sounds, it has happened before. Look at my original post, I asked to see if it compiles is all, not for anyone to "do" my homework as you're obviously trying to state.
Thanks again.
it's your homework to get it to compile, so go ahead and fix it.
If you'd known the first thing you'd known that something that fails at one platform will fail at all of them (barring errors in the implementation of the platform).
You'd also have known that you shouldn't attack those you're asking for help, which you're doing, and which is the halmark of the homework kiddo (so that we'd have recognised you as one even if we'd not done so before).
If you'd known the first thing you'd known that something that fails at one platform will fail at all of them (barring errors in the implementation of the platform).
You'd also have known that you shouldn't attack those you're asking for help, which you're doing, and which is the halmark of the homework kiddo (so that we'd have recognised you as one even if we'd not done so before).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Mar 2008
Posts: 10
Reputation:
Solved Threads: 0
I understand where you are all coming from but take into consideration that the other person called me a liar and made it look as if I had a hidden agenda with my original post which is not the case at all.
Also, I understand that Java is platform independent but have created homework at home, fixed any errors as best I could, took it to school to school to fix any remaining errors and it's compiled and ran correctly. That was the reason for my original post.
I did not "attack" the other poster in my opinion and apologize to that person if it may have seemed that way. And please don't assume I am a child just because I am a programming novice.
Thanks again for all the help.
Also, I understand that Java is platform independent but have created homework at home, fixed any errors as best I could, took it to school to school to fix any remaining errors and it's compiled and ran correctly. That was the reason for my original post.
I did not "attack" the other poster in my opinion and apologize to that person if it may have seemed that way. And please don't assume I am a child just because I am a programming novice.
Thanks again for all the help.
![]() |
Similar Threads
- Moving files in c and c++ (C++)
- Programming FAQ - Updated 1/March/2005 (Computer Science)
- Problem with java (Java)
- Can someone debug my program??? (C)
- File Saves (Python)
- Collating (Java)
- Using Global Low-Level Hooks Without Using A Dll (Computer Science)
- Sides And Collate (Java)
Other Threads in the Java Forum
- Previous Thread: can you help me on how i can do this project?plz...
- Next Thread: Threads - need little help
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






