0

I have two classes: I cannot get either of them to compile in command line: I'm using the javac SodaCan.java prompt but it still wont compile, it says stuff like: "error: Class, interface, or enum expected" for double, sodaCan, getvolume etc.

public SodaCan{
    private double sArea;
    private double volume;

    public SodaCan(double height, double radius){
        getSurfaceArea(height);
        getVolume(radius);
    }

    public double getSurfaceArea(double height, double radius){
        sArea = 2*Math.PI * Math.pow(radius, 2) + 2 * Math.PI * radius * height;

        return sArea;
    }

    public double getVolume(double height, double radius){
        volume = Math.PI * Math.pow(radius, 2) * height;
    }
}

and

import java.util.*;

public class testSodaCan{
    public static void main(String[] args){
        double height, radius;
        Scanner s = new Scanner(System.in);
        System.out.println("Please  input the height of the can: ");
        height = s.nextDouble();
        System.out.println("Please  input the width of the can: ");
        radius = s.nextDouble();
        SodaCan  can = new SodaCan(height, radius);
    }
}
4
  • 2
    how are you compiling? post the exact command Commented Feb 10, 2015 at 12:38
  • 1
    From where are you compiling? Commented Feb 10, 2015 at 12:38
  • @codeMan typing "javac sodaCan.java" Commented Feb 10, 2015 at 12:40
  • 3
    @Ceri it needs to be javac SodaCan.java as you named your class so Commented Feb 10, 2015 at 12:41

1 Answer 1

6

Add the class keyword

public class SodaCan {
Sign up to request clarification or add additional context in comments.

4 Comments

ah.. how did I forget.
and how I didnot see that:D although you are java programmer but you could see sharp :D
And how could eclipse compile that?
I worked at home and then transferred it via the cloud to university, must of accidently transfered an old copy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.