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

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

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:

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.

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?

Are we talking of Java here ?

Then shouldn't this

public static void main()

Be this:-

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:-

int hours = 0;
		double fees = 0.0;
		double rate = 0.0;
		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.

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.

commented: Exactly what I was about to post. +11

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

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.

Wrong. That code would not compile on any JVM for any platform. You stated that it did and masijade's response was completely correct.

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

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.

commented: homework kiddo that just doesn't get it -4

He called you a liar because you ARE a liar. You state your code compiles on one platform and not another, and that's a clear lie if there ever was one.
Behave yourself, you're just a homework kiddo like so many others. If you weren't a kiddo you'd not be as immature as you quite obviously are.

Someone calls me a liar, I defend myself and that makes me a kiddo? You people make me sick.

Don't worry, this will my last post on this forum.

You stated an obvious falsehood as fact, how is that not a lie? What is there to defend? Admitting it would have evoked a better response.

so it's not just a kiddo, but a sicko as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.