I did this java program, i just want someone to correct it.
In this exercise, you will be writing a simple java program to explore using multi methods. The program is consists of one class (MultiMethods). It will hold more than one methods. The purpose of the program is to calculate and display the volume, area, and perimeter of a cube. The length of the cube will be collected from the keypad. For each calculation, you must have a corresponding method. As such, your program will have 4 methods including the main() method.
my java program is
public static void main(String[] args) {
Scanner in= new Scanner(System.in);
System.out.println("Enter the length: ");
int side = in.nextInt();
multimethods Methods = new multimethods(side);
System.out.println("Area = " + Methods.getArea());
System.out.println("Perimeter = " + Methods.getPerimeter());
System.out.println("Volume = " + Methods.getvolume());
}
public static class multimethods {
private final int side;
multimethods(int side) {
this.side = side;
}
double getArea() {
return 6 * (side * side);
}
double getPerimeter() {
return 4 * (side);
}
double getvolume(){
return side * side * side;
}
}
3 answers
I think your class declaration is messed up though.
Did you actually run it?
google is your friend. You can use it to find many code snippets online, doing practically anything you can want. And don't forget the excellent java documentation.