Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-19-2011, 07:48 PM   PM User | #1
J.Wilson
New to the CF scene

 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
J.Wilson is an unknown quantity at this point
What's wrong with my code?

What is wrong with this? I get an error saying there is no main type.

Calc.java
Code:
package Calcer;

public class Calc {
	
	public static void Main(String[] args) {
		//read score
		System.out.println("How many points did you get?");
		double pointsRecieved = InputClass.readDouble();
		System.out.println("What was the number of points possible?");
		int pointsPossible = InputClass.readInt();
		//calculate percentage
		double dec = 100*(pointsRecieved/pointsPossible);
		int percent = (int)dec;
		System.out.println("You got " + percent + " percent!");
		//calculate letter grade
		if (percent >= 92) {
			System.out.println("You got an A!");
		} else if (percent >=82) {
			System.out.println("You got a B!");
		} else if (percent >= 72) {
			System.out.println("You got a C.");
		} else if (percent >= 62) {
			System.out.println("You got a D.");
		} else {
			System.out.println("You got an F.");
		}
		
	}
}
and InputClass.java
Code:
package Calcer;

import java.io.*;

public class InputClass {
	
	public static String readString() {
		BufferedReader br
			=new BufferedReader(new InputStreamReader(System.in), 1);
		String string = " ";
		try {
			string = br.readLine();
		}
		catch (IOException ex) {
			System.out.println(ex);
		}
		return string;
	}
	
	public static int readInt() {
		int integer = Integer.parseInt(readString());
		return integer;
	}
	
	public static double readDouble() {
		double dub = Double.parseDouble(readString());
		return dub;
	}

}
J.Wilson is offline   Reply With Quote
Old 10-20-2011, 12:34 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You should be more specific on the error. This should throw a NoSuchMethodError on main. You do not have a main method; you have a Main method but not a main.
Fou-Lu is offline   Reply With Quote
Old 10-20-2011, 06:36 AM   PM User | #3
zabjade
New to the CF scene

 
Join Date: Sep 2011
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
zabjade is an unknown quantity at this point
Fou-Lu is right. I ran your code and got the same error, then changed Main to main, and it works perfectly. Whenever I have code that doesn't work, I do three things: check spelling, check capitalization, make sure that I'm using == when needed instead of =.
zabjade is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:53 AM.


Advertisement
Log in to turn off these ads.