Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part I: Write a Java class named Pencil.java to represent a pencil type Create a new Java class named Pencil that has the following fields:

Part I:

Write a Java class named Pencil.java to represent a pencil type

Create a new Java class named Pencil that has the following fields:

color, brand, price (use appropriate data type)

In addition, the Pencil class should have the following methods. Constructor - The constructor should accept the color, brand, price as arguments These values should be used to initialize the pencil color, brand, and price Getter Methods and setter methods for all instance variables toString method which returns info about the pencil in the following format: PencilColor Brand unitPrice

For example:

Black BIC $0.90

Part II:

Create a class named PencilBox. There are 10 pencils in each PencileBox with two mixed colors (at your choice). NOTE: if a client program tries to place more than or less than 10 pencils, your program should set the quantity of each type of pencils to 5.

The PencilBox has the following fields and methods Pencil type1, Pencil type2, int qty1, int qty2

Constructor(Pencil type1, int qty1, Pencil type 2, int qty2) getter and setter methods

a method: public double grandTotal(), which returns grand total cost (total price of the pencils in a pencilBox)

overwrite the toString method which returns the info about pencils in the box. For example, there are 5 brown and 5 black color pencils in a pencilBox, the unit price for a brown color pencil is $0.90 and $0.80 for black ones. Then the toString method return a String as shown below:

Brown BIC $4.50

Black CIS201 $4.00

Part III:

Write driver (tester) class named SchoolBag.java that uses your Pencil and PencilBox class:

1. create two pencil objects

2. create a PencilBox object that uses the pencil object created in step 1

3. printout th pencilBox as follows Color Brand Subtotal

-------- --------- ----------

Brown BIC $4.50

Black CIS201 $4.00

--------------------------------------

Grand Total: $8.50

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions