Ceri Westcott
Ceri Westcott

Reputation: 300

Cannot get a program to compile in command line but worked on Eclipse?

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

Upvotes: 0

Views: 90

Answers (1)

Reimeus
Reimeus

Reputation: 159864

Add the class keyword

public class SodaCan {

Upvotes: 6

Related Questions