Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

Based on the error message you are receiving it seems like you are missing the main metho... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Programming With Java A Problem Solving Approach

Authors: John Dean

3rd International Edition

1260575241, 9781260575248

More Books

Students also viewed these Programming questions