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;

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:

  1. Createa Java class namedPackage that contains the following:
  2. Packageshould havethreeprivateinstance variablesof typedoublenamedlength, width, and height.
  3. Packageshould have oneprivateinstance variable of the typeScannernamedinput, initialized toSystem.in.
  4. No-args(explicit default)publicconstructor, which initializes all three double instance variables to 1.0.
  5. Initial(parameterized)publicconstructor, which defines three parameters of typedouble, namedlength,width, andheight, which are used to initialize theinstance variables of same name.
  6. Public copyconstructor, with a parameter of typePackage, used to duplicate an existingPackageobject.
  7. Threepublic voidmethods namedinputLength,inputWidth, andinputHeight.Each method will prompt the user for the appropriate property, and input adoublevalue using theScannerobjectinputto initialize the instance variables
  8. Apublic voidmethod nameddisplayDimensionswhich printsthe dimensions as length X width X height (each value separated by a" X").
  9. 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!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Based on the error message you are receiving it seems like you are missing the main metho... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!