Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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;
    	}
    
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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 =.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •