Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write in java Questions: 1. A coffee shop called DrCoffeeCup needs your support by writing a Java program that helps DrCoffeeCup to sell its coffee

write in java

image text in transcribed

image text in transcribed

image text in transcribed

Questions: 1. A coffee shop called "DrCoffeeCup" needs your support by writing a Java program that helps DrCoffeeCup to sell its coffee according to the following requirements: a. DrCoffeeCup sells different types of coffee as the following: b. DrCoffeeCup has three sizes of cups: small, medium, and large. - The medium size increases the cup price by 0.3. - The large size increases the cup price by 0.5. Use OOP concepts to write a program that helps DrCoffeeCup to sell the above items. You need to start with a super class called SuperCoffeeClass. The SuperCoffeeClass should have: - setSize (...) which changes the cups size. - getPrice() which return the price of the cup based on its size. - other appropriate fields and methods that you need. For example (the parameters are hidden for the constructor and the method setPrice): public class CoffeeTestClass \{ public static void main(String[] args) \{ EspressoCup espressoCupVariable = new EspressoCup( espressoCupVariable.setSize ( espressoCupVariable.getPrice(); ); \} 2. Write a method that counts the number of instances that are created. For example: public class CoffeetestClass \{ public static void main(String[] args) \{ EspressoCup espressoCupVariable = new EspressoCupl CappuccinoCup cappuccinoCupVariable_ 1= new CappuccinoCup( CappuccinoCup cappuccinoCupVariable_2 2 new CappuccinoCupl )i int espressoCupVariableByespressoCupVariable = espressoCupVariable. getCountCup(); int espressoCupVariableCappuccinoCupVariable_ 1= cappuccinoCupVariable 1. getCountCup(): int espressoCupVariableCappuccinoCupVariable_ 2= cappuccinoCupVariable 2.getCountCup(); System.out.printin("Total number of cups: "+espressoCupVariableByespressoCupVariable); System.out. printin("Total number of cups: "+espressoCupVariableByespressoCupVariable); System.out.printin("Total number of cups: "+espressoCupVariableByespressoCupVariable); 3 3 The method is found in all coffee classes, and it increases the total when a coffee cu is defined. The above code will result in the following: Total number of cups: 3 Total number of cups: 3 Total number of cups: 3 3. Improve the SuperCoffeeClass to allow customer to buy other items: All SuperCoffeeClass's items including coffee cups have getPrice(). For example, Majeed has ordered three items and the total price is 24 Riyals: public static void main(String[] args) \{ item1; item 2; item3; //The order of Majeed: item1 = new EspressoCup ( ) ); item2 = new CheeseCake( item3 = new Croissant( double total = item 1.getPrice()+item3.getPrice()+item3.getPrice(); System.out.println("The order of Majed is "+total +" R.S."); The green box refers to the same type for all the three items. So, its not possible to define the type of iteml as EspressoCup and the type of item 2 as CheeseCake. The above code will result in the following: The order of Majed is 24.0 R.S. Bonus: Improve your code by implementing a discount method that has the following: a. The default discount is 0 . b. When customer buys three cups of coffee, the discount is 5 R.S. c. The discount will be applied to any multiple of 3 such as

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 For Advanced Applications 15th International Conference Dasfaa 2010 International Workshops Gdm Benchmarx Mcis Snsmw Diew Udm Tsukuba Japan April 2010 Revised Selected Papers Lncs 6193

Authors: Masatoshi Yoshikawa ,Xiaofeng Meng ,Takayuki Yumoto ,Qiang Ma ,Lifeng Sun ,Chiemi Watanabe

2010th Edition

3642145884, 978-3642145889

More Books

Students also viewed these Databases questions