Question: Given the following class: public abstract class Cake1 { protected String name; protected double rate; public Cake1 (String n, double r) { name = n;

Given the following class:

public abstract class Cake1

{ protected String name;

protected double rate;

public Cake1 (String n, double r)

{

name = n;

rate = r; }

public abstract double calcPrice();

public String toString()

{

return String.format(%s %f , name, rate);

}}

  1. Based on class Cake1 and the following table, define TWO (2) subclasses named as orderCake1 and readymadeCake1.

OrderCake1

ReadymadeCake1

Additional attribute

weight(kg)

quantity

Price calculation

rate*weight

rate*quantity

  1. By using classes definition from a), write an application program that will:

i) declare an array of 4 cake objects (both order and readymade); ii) input data for cake objects and store them into the array; iii) display the total price for all types of cakes; iv) display the total price and the quantity sold for readymade cakes;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!