Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: I am really stuck...my friends have no idea how...

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I am really stuck...my friends have no idea how...

    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


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: I am really stuck...my friends have no idea how...

    I have a clear idea on how to start on creating a class
    Then you are far from lost. Create whatever classes you need, and ask a more specific question about where you are lost, post an SSCCE, post code, compile errors, exceptions thrown, etc...and you will receive a more defined and helpful answer. Suggested reading: How to ask questions

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I am really stuck...my friends have no idea how...

    Hi there!!! Thanks for the reply... a more detailed explanation would be in the screen-shots taken for the outputs

    Untitled.jpg

    Untitled 1.jpg

    Untitled 2.jpg

    Untitled 3.jpg

    Untitled 4.jpg

    Untitled 5.jpg

    Untitled 6.jpg

    Untitled 7.jpg

    Untitled 8.jpg

    Untitled 9.jpg

    Untitled 10.jpg

  4. #4
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: I am really stuck...my friends have no idea how...

    Firstly, Posting your assignment specification sheet isn't going to help anyone.
    Even if it was helpful information, A 500x300 image containing text isn't even readable.

    Please try and follow what copeg suggested and come back after doing so.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

Similar Threads

  1. hello friends
    By bjcool143 in forum Member Introductions
    Replies: 0
    Last Post: January 8th, 2011, 05:46 AM
  2. Looking for algorithm idea help
    By Maineiac in forum Algorithms & Recursion
    Replies: 5
    Last Post: November 18th, 2010, 07:38 PM
  3. No idea what to do for this
    By jwb4291 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: July 18th, 2010, 07:16 PM
  4. hii friends....
    By khader in forum Member Introductions
    Replies: 2
    Last Post: July 15th, 2010, 07:09 AM
  5. hi friends
    By bsrk315 in forum Member Introductions
    Replies: 0
    Last Post: April 20th, 2010, 03:36 PM