Hi everyone!!! I am new here, I recently happened to to be real stuck at this problem i have!!!
My friends have no idea how to do so i am pretty lost....
A Cake Shop sells five flavors of cake -- Strawberry, Chocolate, Vanilla, Almond and Durian. The shop has approached you to write a program for one of their newly designed self-service machine.
The customer will first choose a cake and pay for it. The machine will dispense 1 dollar, 50 cents, 20 cents and 10 cents coins depending on the price of the cake and the payment received from the customer.
a) Write a Java class Cake to represent the cake object:
▪ String type represents the flavor of the cake
▪ int price represents the price of the cake
▪ int nCakes represents the no. of cakes available
Add a constructor and appropriate get or set methods to the class if necessary.
b) Write a Java class SelfServiceMachine to represent the machine. The class should have methods that will be invoked by the main method to read user input, check the availability of the cake, read the payment, compute and display the change and the coins dispensing …., etc.
The following methods are recommended:
▪ readChoice(): displays the 5 type of cakes, their prices and the number of cakes available, it reads the choice of cake entered by the user. The method validates the user input and prompts for re-input if the input is invalid.
▪ readPayment(): reads the payment. The valid range of payment should be more than or equal to the price. The method validates the user input and prompts for re-input if the value is invalid.
▪ computerAndDisplayChange(): computes and displays the change. Change is computed as the difference between payment and price.
▪ computeAndDisplayCoins( ): computes and displays the number of 1 dollar, 50 cents, 20 cents and 10 cents coins to be dispensed base on the change.
Add a constructor and other methods in the class if necessary.
c) Write a Java class MachineUser that contains the main() method for the entire application. The main() method is where your program will start to run. It calls the methods in SelfServiceMachine class to display the menu, read user’s choice, display the price, take in the payment and display the changes…
d) You should make use of arrays for coding efficiency.
I have a clear idea on how to start on creating a class but i am not sure how to write the constructors for it...
Hence I am really lost.....
I hope someone will help me