Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The task: Directions: Create a bluej project called Homework4 that implements the classes described below. Pizza class: The Pizza class represents a pizza order. It

The task: Directions: Create a bluej project called Homework4 that implements the classes described below. Pizza class: The Pizza class represents a pizza order. It has fields to store the customers name, pizza size, number of toppings, and cost of the pizza. Write the Pizza class with these requirements:

Add the 4 fields used by this class. All fields should be set to private, and use descriptive variable names.

Create a constructor that takes 3 parameters: a String to initialize the customer name, a String to initialize the pizza size (small, medium, or large), and an int to initialize the number of toppings. Initialize the cost using the calculateCost method described below.

Write an accessor method named getName that returns the name from the order.

Write a mutator method named calculateCost to calculate the cost of the pizza order as follows: A small pizza is $8, and toppings are $1 each. A medium pizza is $10, and toppings are $2 each. A large pizza is $12, and toppings are $3 each. Additionally, if the customer orders 4 or more toppings, there is a $2 discount of the price of the pizza, regardless of the size. This method will set the cost of the pizza.

Write an accessor named getCost that returns the cost of the pizza.

Write a mutator method named applyDiscount that takes an int parameter and reduces the cost of the pizza by the parameter amount.

Write a method named printDetails that will print out the Pizza object details as shown below: Bales, medium 3-topping pizza: $16

Orders class: The Orders class represents a number of orders for a pizza shop. It has 4 fields: three Pizza objects, and one String field that stores a day of the week.

Add the four (4) fields for this class.

Add the constructor for this class. It takes one String parameter to set the day of the week. Within the constructor, initialize the Pizza objects as follows: (Bales, medium, 3), (Marts, small, 2), (Donal, large, 6).

Add a method, applyCoupon, that takes one String parameter, a name. It will match the name to the customer name of one of the Pizza objects, and apply a discount of $1, $2, or $3. The amount should be chosen randomly. If there is no Pizza object with this name, an appropriate error message should be printed.

Add a method called printOrders that will do the following 3 things:

Apply a coupon to the order for Donal

Calculate the total price for all three pizza orders.

Print out the orders as shown below: Pizza orders for Wednesday Bales, medium 3-topping pizza: $16 Marts, small 2-topping pizza: $10 Donal, large 6-topping pizza: $25 --------------------------------------- Total sales for Wednesday: $51

Keep in mind that your total may be different since the coupon amount was random.

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

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions