When I try to run the program below I keep receiving an error: import java.util.Scanner; public class
Question:
When I try to run the program below I keep receiving an error:
import java.util.Scanner;
public class Package { private double length; private double width; private double height; private Scanner input = new Scanner(System.in);
public Package() { this.length = 1.0; this.width = 1.0; this.height = 1.0; }
public Package(double length, double width, double height) { this.length = length; this.width = width; this.height = height; }
public Package(Package pkg) { this.length = pkg.length; this.width = pkg.width; this.height = pkg.height; }
public void inputLength() { System.out.println("Please enter the length: "); this.length = input.nextDouble(); }
public void inputWidth() { System.out.println("Please enter the width: "); this.width = input.nextDouble(); }
public void inputHeight() { System.out.println("Please enter the height: "); this.height = input.nextDouble(); }
public void displayDimensions() { System.out.println(this.length + " X " + this.width + " X " + this.height); }
public double calcVolume() { double vol = this.length * this.width * this.height; return vol; } }
I keep getting this:
"Error: Main method not found in class Package, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application"
These are the rules I was given:
- Createa Java class namedPackage that contains the following:
- Packageshould havethreeprivateinstance variablesof typedoublenamedlength, width, and height.
- Packageshould have oneprivateinstance variable of the typeScannernamedinput, initialized toSystem.in.
- No-args(explicit default)publicconstructor, which initializes all three double instance variables to 1.0.
- Initial(parameterized)publicconstructor, which defines three parameters of typedouble, namedlength,width, andheight, which are used to initialize theinstance variables of same name.
- Public copyconstructor, with a parameter of typePackage, used to duplicate an existingPackageobject.
- Threepublic voidmethods namedinputLength,inputWidth, andinputHeight.Each method will prompt the user for the appropriate property, and input adoublevalue using theScannerobjectinputto initialize the instance variables
- Apublic voidmethod nameddisplayDimensionswhich printsthe dimensions as length X width X height (each value separated by a" X").
- Apublicmethod of typedoublenamedcalcVolumethat calculates the volumeand returns the result as adoublevalue.
I really don't know what I'm doing wrong or if I'm setting the class up wrong. File name Package.java. Please help!
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean