Please check if this compiles in Windows.

Reply

Join Date: Mar 2008
Posts: 10
Reputation: Saaddani is an unknown quantity at this point 
Solved Threads: 0
Saaddani Saaddani is offline Offline
Newbie Poster

Please check if this compiles in Windows.

 
0
  #1
Sep 15th, 2008
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

  1. import java.io.*;
  2. import java.text.DecimalFormat;
  3. import java.util.*;
  4.  
  5. public class Tuition
  6. {
  7.  
  8. public static void main()
  9. {
  10. int hours = 0;
  11. double fees = 0.0;
  12. double rate = 0.0;
  13. double tuition = 0.0;
  14.  
  15. displayWelcome();
  16. hours = getHours();
  17. rate = getRate(hours);
  18. tuition = calcTuition(hours, rate);
  19. fees = calcFees(tuition);
  20. displayTotal(tuition + fees);
  21.  
  22. } //end of main()
  23.  
  24. public static void displayWelcome()
  25. {
  26. System.out.println("Welcome to Dannys Tuition Calculator!");
  27. } //end displayWelcome()
  28.  
  29. public static int getHours()
  30. {
  31. String strHours;
  32. int hours = 0;
  33.  
  34. Scanner scannerIn= new Scanner(System.in);
  35.  
  36. System.out.print("Please enter the total number of hours: ");
  37. strHours = scannerIn.next();
  38. hours = Integer.parseInt(strHours);
  39. // add try + catch statement
  40. return hours;
  41. } //end of getHours()
  42.  
  43. public static double getRate(int hours)
  44. {
  45. if (hours > 15)
  46. {
  47. rate = 44.5;
  48. }
  49. else
  50. {
  51. rate = 50.00;
  52. }
  53. return rate;
  54. } //end of getRate
  55.  
  56. public static double calcTuition(int hour, double rate)
  57. {
  58. tuition = rate * hours;
  59. return tuition;
  60. } //end of calcTuition()
  61.  
  62. public static double calcFees(double tuition)
  63. {
  64. fees = tuition * 0.08;
  65. return fees;
  66. }//end of calcFees()
  67.  
  68. public static void displayTotal(double total)
  69. {
  70. DecimalFormat twoDigits = new DecimalFormat("$#,000.00");
  71.  
  72. System.out.println("The total cost of tuition is: " + twoDigits.format(total) + ".");
  73. } //end of displayTotal()
  74. } //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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 203
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training

Re: Please check if this compiles in Windows.

 
0
  #2
Sep 15th, 2008
  1. public class Tuition
  2. {
  3.  
  4. public static void main()
  5. {
  6. int hours = 0;
  7. double fees = 0.0;
  8. double rate = 0.0;
  9. double tuition = 0.0;
  10.  
  11. displayWelcome();
  12. hours = getHours();
  13. rate = getRate(hours);
  14. tuition = calcTuition(hours, rate);
  15. fees = calcFees(tuition);
  16. displayTotal(tuition + fees);
  17.  
  18. } //end of main()

OK, you need to change it to this:

  1. public class Tuition
  2. {
  3. static int hours = 0;
  4. static double fees = 0.0;
  5. static double rate = 0.0;
  6. static double tuition = 0.0;
  7.  
  8. public static void main()
  9. {
  10. displayWelcome();
  11. hours = getHours();
  12. rate = getRate(hours);
  13. tuition = calcTuition(hours, rate);
  14. fees = calcFees(tuition);
  15. displayTotal(tuition + fees);
  16.  
  17. } //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
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 10
Reputation: Saaddani is an unknown quantity at this point 
Solved Threads: 0
Saaddani Saaddani is offline Offline
Newbie Poster

Re: Please check if this compiles in Windows.

 
0
  #3
Sep 16th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Please check if this compiles in Windows.

 
0
  #4
Sep 16th, 2008
Are we talking of Java here ?

Then shouldn't this
  1. public static void main()

Be this:-
  1. 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:-
  1. int hours = 0;
  2. double fees = 0.0;
  3. double rate = 0.0;
  4. double tuition = 0.0;
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.
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 ?"
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,356
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Please check if this compiles in Windows.

 
1
  #5
Sep 16th, 2008
And this

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?
is obviously a lie, as that code is guaranteed to fail to compile on every platform.
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 203
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training

Re: Please check if this compiles in Windows.

 
0
  #6
Sep 16th, 2008
Originally Posted by stephen84s View Post
@llemes4011
Do not give people ready to eat food, teach them how to hunt for it.
sorry, it was late, i needed to get to bed, and i was going to come and explain my self now, but it seems that you pretty much said everything, sorry >.<
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 10
Reputation: Saaddani is an unknown quantity at this point 
Solved Threads: 0
Saaddani Saaddani is offline Offline
Newbie Poster

Re: Please check if this compiles in Windows.

 
0
  #7
Sep 16th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,438
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Please check if this compiles in Windows.

 
0
  #8
Sep 16th, 2008
Wrong. That code would not compile on any JVM for any platform. You stated that it did and masijade's response was completely correct.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Please check if this compiles in Windows.

 
0
  #9
Sep 16th, 2008
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).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 10
Reputation: Saaddani is an unknown quantity at this point 
Solved Threads: 0
Saaddani Saaddani is offline Offline
Newbie Poster

Re: Please check if this compiles in Windows.

 
-1
  #10
Sep 16th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC