Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java programing using NetBean The second programming project involves writing a program that computes the sales tax for a collection of automobiles of different types.

Java programing using NetBean

The second programming project involves writing a program that computes the sales tax for a collection of automobiles of different types. This program consists of three classes and the Program Core. The first class is the Automobile class, which contains the automobiles Make and Model [one data element] and purchase price, which is specified in whole US dollars. It should have three methods:

  1. A constructor that allows the Make and Model and purchase price to be initialized.
  2. A method named salesTax that returns the base sales tax computed as 5% of the sales price.
  3. A toString method that returns a string containing the Make and Model of the automobile, the sales price, and the sales tax, appropriately labeled.

The Automobile class has two subclasses. The first subclass is Electric. It has an additional instance variable that contains its weight in pounds stored as an integer. It should have the same three methods:

  1. A constructor that allows the automobiles Make and Model, purchase price and weight to be initialized.
  2. An overridden method salesTax that returns the total sales tax. The sales tax for an Electric Automobile consists of the base sales tax of 5% that applies to all automobiles minus a discount. If the weight is 3,000 pounds or less the discount is $200; otherwise it is $150.
  3. An overridden toString method that returns a string containing the Make and Model of the automobile, the sales price, sales tax and the weight, appropriately labeled.

The second subclass is Hybrid. It has an additional instance variable that contains the number of miles per gallon stored as an integer. It should have the same three methods:

  1. A constructor that allows the automobiles Make and Model, purchase price and miles per gallon to be initialized.
  2. An overridden method salesTax that returns the total sales tax. The sales tax for a Hybrid Automobile consists of the base sales tax of 5% minus a discount. If the number is 40 mpg or less, the discount is $100; otherwise there is an additional discount of $2.00 for every mile per gallon in excess of 40 mpg.
  3. An overridden toString method that returns a string containing the Make and Model of the automobile, the sales price, sales tax and the number of miles per gallon, appropriately labeled.

No additional public methods should be included in any of the above three classes. Finally, the Program Core contains the main method. It should generate the GUI too. After entering the information about the Make and Model, its sales price, and selecting the type of the automobile, clicking the Compute Sales Tax button displays the sales tax in the TextField to its right. The default Automobile Type is Other so that radio button in the radio group should be selected. When Other Type is selected the Labels and TextFields for Hybrid and Electric are hidden. [Hints: [Component].setVisible(false).];[Component].setEditable(false)] When Hybrid Type is selected the Miles per Gallon Label and the its TextField display but are hidden if not selected. When Electric Type is selected the Weight in Pounds Label and its TextField display but are hidden if not selected. If non-integer values are entered in any of the fields that require integers, an error message should be displayed in a JOptionPane window and after clicking OK the cursor returns to the same TextField. In addition, the object should be stored in an array of type Automobile. That array should contain at least five automobiles entries/records/rows. Clicking the Clear Fields button should clear all TextFields and hide the Labels and TextField for the Hybrid and Electric Types. Clicking the Display Report button should produce in the output window the information about all the automobiles stored in the array during the processing of the program. An example of the report that should be displayed is shown below:

Make and Model: Toyota Prius

Sales Price: 30000.00

Sales Tax: 1390.00

Vehicle Type: Hybrid

Vehicle Unique (MPG): 45

Total Cost: 31390.00

Make and Model: Ford Fusion

Sales Price: 21000

Sales Tax: 1050.00

Vehicle Type: Other

Vehicle Unique (None): 0

Total Cost: 22050.00

Make and Model: Chevrolet Bolt

Sales Price: 32000

Sales Tax: 1450.00

Vehicle Type: Electric

Vehicle Unique (Weight): 3250

Total Cost: 33450.00

For design purposes, it might be helpful to include an Exit button on the GUI Interface. Be sure to follow good programming practices, which means making all instance variables private, naming all constants and avoiding the duplication of code. Furthermore, you must select enough different kinds of automobiles in your Test Plan to completely test the program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago

Question

d. How were you expected to contribute to family life?

Answered: 1 week ago