PROBLEM 1: Your whole program should contain three java files: Hw6.java, Stock.java, UsedStock.java. Assume, you are a

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

PROBLEM 1: Your whole program should contain three java files: Hw6.java, Stock.java, UsedStock.java. Assume, you are a

Post by answerhappygod »

PROBLEM 1:
Your whole program should contain three java files:
Hw6.java, Stock.java,
UsedStock.java.

Assume, you are a manager of BP car dealership and want to develop
inventory management system.
Develop your inventory management system following the steps
below.

Step 1: Stock class (10pt)

This class is for the new vehicle inventory that your dealership
directly purchases from BP motor. Create
a class called Stock and save it in Stock.java.

The class has the following (private) instance variables:
• An integer variable for stock ID;
• A double variable for purchase price;
The class has the following (public) instance methods:
• Constructor method (Version 1), with no argument:
o Simply set stock ID to 0, and set purchase price to 0;
• Constructor method (Version 2), with two arguments: one for stock
ID, one for purchase price
o Set the stock ID and the purchase price equal to the parameter
values;
• A method to set the stock ID;
• A method to set the purchase price;
• A method to retrieve the stock ID;
• A method to retrieve the purchase price;
• A method to print stock information:
o Print stock ID and purchase price in one line, in a properly
aligned format (see the
screenshot in Step 2; use printf).

Step 2: UsedStock class (10pt)

This class is for the used vehicle inventory that your dealership
purchases from consumers whey they buy
a new car. However, you may need to repair the used vehicle and the
repair costs should be recorded as
well. Create a class called UsedStock and save it in
UsedStock.java.

The UsedStock class inherits from the general Stock class.
• It has an additional (private) double variable, which records the
repair cost.

In addition, you need to define the following methods for the
UsedStock class:
• Constructor method, with three parameters: stock ID (int),
purchase price (double), and repair cost
(double)
o Note: Think carefully how to initialize stock ID and purchase
price, as they are private
variables of the superclass (i.e. Stock class).
• Override the method that prints stock information
o For a used stock, in addition to printing its stock ID and
purchase price, also display the
repair cost as follows: “(Repair cost; $600)”
o Note: The string “Repair cost” can be displayed as is (i.e. you
don’t need to create a variable
for it); the actual dollar amount (e.g. 600) needs to be the value
of the double variable.
o Note: Think carefully how to print stock ID and purchase price as
they are private variables.

Step 3: Program Entry Point: Main Method (10pt)

Create a class called Hw6 that only contains the main method as the
entry point of your whole JAVA
program. Save the class in Hw6.java.

In your main method, do the following:
• Create an array of 5 Stock objects;
• Create each of the array elements as follows:
o Instantiate the first array element by using the constructor
method (Version 2) to create a
Stock object with stock ID 1001, and purchase price 15342.68;
o Instantiate the second array element by using the constructor
method (Version 2) to create
a Stock object with stock ID 1002, and purchase price
14112.56;
o Instantiate the third array element by using the constructor
method (Version 1) to create a
(blank) Stock object. Then call the “setter” methods to set the
stock ID to 1003 and the
purchase price 16121.55;
o Instantiate the fourth array element by using the constructor
method (Version 1) to create
a (blank) Stock object. Then call the “setter” methods to set the
stock ID to 1004 and the
purchase price 12756.18;
o Instantiate the fifth array element by creating a UsedStock
object with Stock ID 1005,
purchase price 6576.33, and repair cost 500;
o Use the for loop to print out all five stocks’ information. In
each loop iteration, let one array
element call the print method.

Your program should have the following output:
Problem 1 Your Whole Program Should Contain Three Java Files Hw6 Java Stock Java Usedstock Java Assume You Are A 1
Problem 1 Your Whole Program Should Contain Three Java Files Hw6 Java Stock Java Usedstock Java Assume You Are A 1 (26.08 KiB) Viewed 21 times
GV. Command Prompt Microsoft Windows [Version 10.0.18362.1016] (C) 2019 Microsoft Corporation. All rights reserved. C:\Userstang>javac Hw6.java C:WUserslKang>java Hw6 Stock ID: 1001Purchase Price: $15342.68 Stock ID: 1002 Purchase Price: $14112.56 Stock 10: 1003 Purchase Price: $16121.55 Stock ID: 1004 Purchase Price: $12756.18 Stock 10: 1005 Purchase Price: $6576.33 (Repair cost; $500.00) C:WUsershkang
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply