CSC186 Lab Assignment 3 – Classes and Array of Object solution

$25.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

3.1 The class Cupcake has the following attributes:
• Name – example: vanilla, red velvet
• Code – example: CV123
• Price per piece
a) Write a complete class called Cupcake with the following methods:
i. Default/Normal/Copy constructors
ii. Mutator method for all data members
iii. Accessor methods for all data members
iv. toString() method to return the objects’ information.
v. priceInDozen(): a method that will return the price of the cupcake.

Discount will be calculated based on the last character of the code.
Otherwise, no discount will be given. The discount rate for each code are
as follows:
Character Rate
‘1’ 5%
‘2’ 8%
‘3’ 10%

Example: discount for a dozen of cupcakes with code CV123 is 10%
b) Write an application class called CupcakeApp to perform the following:
i. Declare and create an array of cupcake objects and store the data onto
array. The size of array will be entered by the user.
ii. Calculate and display the net price of cupcakes.
iii. Calculate and display the total price of all cupcakes.

3.2 Given the Fruit class with the following data members attributes):
Class name : Fruit
Attributes : String name; //fruit name
String type; //local or imported
double weight; //in kg
double price; //price per kilogram
Method : constructor, mutator, accessor, processor, printer

a) Write the definition of the following methods:
i. Default/Normal/Copy Constructor.
ii. Mutator/Setter for each attribute.
iii. Getter/Accessor/Retriever for each attribute.
iv. A Processor method named isLocal() that returns true if it is local fruit
or returns false otherwise.

v. A processor method named calcTotalPrice() calculates and returns
the total price of the fruit. In order to encourage the buyers to buy the local
fruits, 3% discount is given on the total price.
vi. Printer method named toString() to return the objects’ information.

b) Write an application program to do the following tasks:
i. Declare an array of object named fruitList and store some data onto
array.
ii. Display the name of local fruits which has the highest price.
iii. Calculate total sale of the imported fruits.

3.3 Given the following class named Furniture.
Class name : Furniture
Attributes : String furnitureType; // e.g. chair, bed, table
String material; //e.g. wood, rattan
double pricePerUnit;
int quantity;
Method : constructor, mutator, accessor, processor, printer

a) Write the definition of the following methods:
i. Default/Normal/Copy Constructor.
ii. Mutator/Setter for each attribute.
iii. Getter/Accessor/Retriever for each attribute.
iv. A Processor method named calcPriceFurniture() to calculate and
returns the price of furniture.

The price is calculated based on the price per
unit, quantity and the discount rates depend on the material types as shown
in the following table:
Material Type Discount Rate
Wood 20%
Rattan 15%
Metal 10%
Bamboo 5%
v. A printer method named toString() to return the objects’ information.

b) Write an application program to do the following tasks:
i. Declare an array of object named arrFurniture and store some data
onto array.
ii. To calculate and display the total price of furniture for each type of material.
iii. To determine the highest price of wood and display the details of
information.