Results 1 to 20 of 20
  1. #1
    creedkorn is offline Member
    Join Date
    Apr 2011
    Posts
    17
    Rep Power
    0

    Default newbie needs help in GUI assignment

    I have to write a Java GUI application that simulates a Nescafe Vending Machine. The simulated machine dispenses the following choices of drinks drinks: latte, white coffee, cappuccino, mocha, and black coffee. Each drink has different cost each to purchase.

    The user interface named MyGUI should provide a Frame showing the simulated machine interface. The machine should have a supply of 10 cups of each of the drinks. It should also have a textfield where the user can enter the amount of money he or she is giving to the machine. The user can click on a button to select a drink to dispense. The application should also display the amount of change it is giving back to the user. It should also keep track of its inventory of drinks and inform user if he or she has selected a drink that is out of stock. Include necessary exceptions handling in your code. Perform also validation on input fields such as selecting a drink with no money entered or selecting a drink with inadequate amount of money.

    I have to define and use a class named Coffee in the application to represent an object of each drink provided by the machine, also include suitable attributes and methods in the class.

  2. #2
    Maximus-EVG is offline Member
    Join Date
    Apr 2011
    Location
    Canada!
    Posts
    30
    Rep Power
    0

    Default

    Read this:
    Introduction to GUI Building - NetBeans IDE 6.9 Tutorial

    Its a step by step tutorial for creating a graphical application with an IDE called NetBeans. Once you create the tutorial app, you will either
    1. Understand how to customize it to create what you need.
    2. Need to read more tutorials from the site.

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I don't know if that link uses the GUI builder or not, if it does, make sure you are allowed to use a GUI builder for this assignment.

    Next step is to ask us specific questions, we won't do it for you, don't just dump your assignment and expect people to give you code.

    One good piece of advice I can give is to work your way up, don't try to tackle the whole thing at once, break it into small steps and get each step working before moving to the next one. For instance, first create the coffee class and test it with out a GUI.

  4. #4
    creedkorn is offline Member
    Join Date
    Apr 2011
    Posts
    17
    Rep Power
    0

    Default

    We're actually using a software called BlueJ and so far, we're only covering basics of GUI; flow, border and grid layouts while implementing action listener. I'm not familiar with netbeans though, and is GUI builder like a GUI wizard ?

  5. #5
    creedkorn is offline Member
    Join Date
    Apr 2011
    Posts
    17
    Rep Power
    0

    Default

    Thanks a lot for the advice. But is it possible to do it with netbeans IDE as Maximus mentioned while actually getting the coding ?

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    GUI building as far as I know let's you shape and place components visually on the screen. I doubt the assignment intends for you to do this. Like I said earlier. Start small and work your way up.

    Also, the GUI builder only lays out the components for you, you will have to do the action handling still and you will still need all the underlying logic and classes. If you use a GUI builder it will most likely use layout managers you are unfamiliar with and your teacher will be able to tell you used it. Before using it make sure it's acceptable.
    Last edited by sunde887; 04-17-2011 at 11:26 AM.

  7. #7
    creedkorn is offline Member
    Join Date
    Apr 2011
    Posts
    17
    Rep Power
    0

    Default

    ok, there's one other question, but it's unrelated to GUI......


    Faith Co. is a well known hypermarket in Bandar Baru Nilai. You are simulating a membership card for Faith Co. A customer could have only one account and would be determined based on their given customer id. A customer could add up points to their card, and could redeem prizes using the points. Each ringgit they spent is equal to one point.

    You are required to declare the classes as below:


    Account
    -owner: Customer
    -accountNo: int
    -balance: double
    + Account()
    + Account(owner: Customer, accountNo: int, balance: double)
    +setOwner(owner: Customer): void
    +getOwner(): Customer
    +setAccountNo(accountNo: int): void
    +getAccountNo(): int
    +setBalance(balance:double): void
    +getBalance(): double
    +addPoint(amount:double):boolean
    +redeemPrize(amount:double):boolean

    Customer
    -name : String
    -idNo : String
    +Customer()
    +Customer(name: String, idNo: String)
    +setName(name: String): void
    +getName(): String
    +setID(idNo: String):void
    +getID():String


    The following are the requirements needed:
    1. addPoint method:
    a. Do a checking on the amount given. Perform the update on current balance point only if the amount is greater than zero. Return true if adding points is successful and false otherwise.

    2. redeemPrize method:
    a. Do a checking on the amount given. Deduct from current points only if the amount is less than the points, and the points after deduction should not be less than 100. Return true if deduction is successful and false otherwise.

    Then create a Prize class that will instantiate an object of type Account and Customer. Request the user to enter the information for the newly created Customer object and Account object.

    Your Prize class then should allow the following options:

    1 – Add Points
    2 – Redeem Prizes
    3 – Check Points
    0 – Exit

    These options should be displayed repeatedly until the user enters 0. Once option 0 is chosen, display a “Thank you” message and terminate from the application.

    Add your own creativity to the system but do not change the basic requirements.

    I need enlightment on what exactly to do, and how to utilise method on the following question.

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You want to make this as small as possible and build got way up. Try making the customer class first, after you finish it, post the code and point out anything you struggled with. Also, be sure to ask specific questions. You wont get people doing this for you, but we are glad to help out.

  9. #9
    creedkorn is offline Member
    Join Date
    Apr 2011
    Posts
    17
    Rep Power
    0

    Default

    Would you please pass me a link or a GUI coding sample similar to the vending machine question, where BlueJ is used.

  10. #10
    creedkorn is offline Member
    Join Date
    Apr 2011
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by sunde887 View Post
    You want to make this as small as possible and build got way up. Try making the customer class first, after you finish it, post the code and point out anything you struggled with. Also, be sure to ask specific questions. You wont get people doing this for you, but we are glad to help out.
    ok, here's what i've done for the 2nd question:

    public class customer {

    private String name;
    private String idNo;

    public customer() {
    name = "John Smith";
    idNo = "FC1";
    }

    public customer(String name, String idNo){
    this.name = name;
    this.idNo = idNo;
    }

    public setName(String name){
    this.name = name;
    }

    public getName(){
    return name;
    }

    public setID(String idNo){
    this.idNo = idNo;
    }

    public getID(){
    return idNo;
    }

    }

  11. #11
    creedkorn is offline Member
    Join Date
    Apr 2011
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by sunde887 View Post
    You want to make this as small as possible and build got way up. Try making the customer class first, after you finish it, post the code and point out anything you struggled with. Also, be sure to ask specific questions. You wont get people doing this for you, but we are glad to help out.
    (Prize class)

    import java.util.Scanner;

    public class Prize
    {
    public static void main(String args[]){

    Scanner input = new Scanner(System.in);


    String name = showInputDialog("Enter name : ");
    String idNo = showInputDialog("Enter id : ");

    Customer xyz = new Customer(name, idNo);

    Customer owner() = xyz;
    int accountNo = showInputDialog("Enter accountNo : ");
    double balance = showInputDialog("Enter balance : ");

    Account abc = new Account(owner(), accountNo, balance);

    int amount = showInputDialog("Enter amount paid : ");
    System.out.println(" Please select an option from the following menu: ");
    System.out.println(" ");
    System.out.println(" 1. Add Points ");
    System.out.println(" 2. Redeem Prizes ");
    System.out.println(" 3. Check Points");
    System.out.println(" 4. Exit ");
    System.out.println();
    System.out.println();
    System.out.print("Please make a selection (1 - 4): ");
    int choice = input.nextInt();
    System.out.println("");

    switch (choice) {
    case 1: account.addPrize(amount, balance); break;
    case 2: account.redeemPrize(amount, balance); break;
    case 3: System.out.println(balance); break;
    case 4: System.exit(); break;
    default: comment = "Invalid choice"; break;
    }
    }
    }

  12. #12
    creedkorn is offline Member
    Join Date
    Apr 2011
    Posts
    17
    Rep Power
    0

    Default

    (Account class)


    public class account {

    private owner = new Customer(name, idNo);
    private int accountNo;
    private double balance;

    public account() {
    owner = (John Smith, FC1);
    accountNo = 12345;
    balance = 20.00;

    }

    public account(Customer owner(), int accountNo, double balance){
    this.owner() = owner();
    this.accountNo = accountNo;
    this.balance = balance;
    }

    public setOwner(Customer){
    this.owner() = owner();
    }

    public getOwner(){
    return owner();
    }

    public setAccountNo(){
    this.accountNo = accountNo;
    }

    public getAccountNo(){
    return accountNo;
    }

    public setBalance(){
    this.balance = balance;
    }

    public getBalance(){
    return balance;
    }

    public addPoint(int x, double balance){
    if (x>0){
    balance = balance + x;
    }
    else{
    System.out.println("There are no points to add");
    }
    }

    public redeemPrize(int x, double balance){
    if (x<balance){
    balance = balance - x;
    }
    else{
    System.out.println("You have insuffecient balance to make that redemption. Keep shopping! :D");
    }
    }

    public test{
    System.out.println("not sure if this works");
    }
    }

  13. #13
    creedkorn is offline Member
    Join Date
    Apr 2011
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by sunde887 View Post
    You want to make this as small as possible and build got way up. Try making the customer class first, after you finish it, post the code and point out anything you struggled with. Also, be sure to ask specific questions. You wont get people doing this for you, but we are glad to help out.
    Apparently, errors were occuring throughout the coding. So could you please help me ?

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Again, what are your specific questions? What are your error messages?

    I suggest you work on one class at a time with us if possible. Also, when posting code, please use formatted code and code tags so we can read it (please see my first signature link below labeled "how to use code tags".

  15. #15
    creedkorn is offline Member
    Join Date
    Apr 2011
    Posts
    17
    Rep Power
    0

    Default

    <public class customer {

    <private String name;
    private String idNo;>

    <public customer() {
    name = "John Smith";
    idNo = "FC1";
    }>

    <public customer(String name, String idNo){
    this.name = name;
    this.idNo = idNo;
    }>

    <public setName(String name){
    this.name = name;
    }>

    <public getName(){
    return name;
    }>

    <public setID(String idNo){
    this.idNo = idNo;
    }>

    <public getID(){
    return idNo;
    }>

    }>



    Error:
    "invalid method declaration; return type required" error at

    <public setName(String name){
    this.name = name;
    }>

  16. #16
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Having trouble with code tags still?

    Do you have any questions about it?

    I suggest you delete your post above and try to repost it with code tags, and again with any specific questions you may have. Again, my link below will show you how to use these tags.

  17. #17
    creedkorn is offline Member
    Join Date
    Apr 2011
    Posts
    17
    Rep Power
    0

    Default

    Originally Posted by creedkorn
    ok, there's one other question, but it's unrelated to GUI......


    Faith Co. is a well known hypermarket in Bandar Baru Nilai. You are simulating a membership card for Faith Co. A customer could have only one account and would be determined based on their given customer id. A customer could add up points to their card, and could redeem prizes using the points. Each ringgit they spent is equal to one point.

    You are required to declare the classes as below:


    Account
    -owner: Customer
    -accountNo: int
    -balance: double
    + Account()
    + Account(owner: Customer, accountNo: int, balance: double)
    +setOwner(owner: Customer): void
    +getOwner(): Customer
    +setAccountNo(accountNo: int): void
    +getAccountNo(): int
    +setBalance(balance:double): void
    +getBalance(): double
    +addPoint(amount:double):boolean
    +redeemPrize(amount:double):boolean

    Customer
    -name : String
    -idNo : String
    +Customer()
    +Customer(name: String, idNo: String)
    +setName(name: String): void
    +getName(): String
    +setID(idNo: String):void
    +getID():String


    The following are the requirements needed:
    1. addPoint method:
    a. Do a checking on the amount given. Perform the update on current balance point only if the amount is greater than zero. Return true if adding points is successful and false otherwise.

    2. redeemPrize method:
    a. Do a checking on the amount given. Deduct from current points only if the amount is less than the points, and the points after deduction should not be less than 100. Return true if deduction is successful and false otherwise.

    Then create a Prize class that will instantiate an object of type Account and Customer. Request the user to enter the information for the newly created Customer object and Account object.

    Your Prize class then should allow the following options:

    1 – Add Points
    2 – Redeem Prizes
    3 – Check Points
    0 – Exit

    These options should be displayed repeatedly until the user enters 0. Once option 0 is chosen, display a “Thank you” message and terminate from the application.

    Add your own creativity to the system but do not change the basic requirements.

    I need enlightment on what exactly to do, and how to utilise method on the following question.

    <public class customer {

    <private String name;
    private String idNo;>

    <public customer() {
    name = "John Smith";
    idNo = "FC1";
    }>

    <public customer(String name, String idNo){
    this.name = name;
    this.idNo = idNo;
    }>

    <public setName(String name){
    this.name = name;
    }>

    <public getName(){
    return name;
    }>

    <public setID(String idNo){
    this.idNo = idNo;
    }>

    <public getID(){
    return idNo;
    }>

    }>



    Error:
    "invalid method declaration; return type required" error at

    <public setName(String name){
    this.name = name;

  18. #18
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Again, your posted is very difficult to read without code tags, again, please read the link below in my signature links on how to use code tags, again, if you are unsure about a specific on how to use code tags, please ask. I'm not sure how I can ask you to follow these recommendations so that you'll believe me and follow through. Your ability to comply with these instructions will help show the forum members that you are strongly motivated to help them help you, and that you are intelligent enough to be able to succeed in programming.

  19. #19
    creedkorn is offline Member
    Join Date
    Apr 2011
    Posts
    17
    Rep Power
    0

    Default

    yeah how do you use them ? i don't understand [code]<script>[code] ? coding inside square brackets ?

  20. #20
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. HW assignment help
    By mackavelirip in forum New To Java
    Replies: 5
    Last Post: 03-31-2011, 03:34 AM
  2. Can somebody help me in this assignment?
    By lulzim in forum New To Java
    Replies: 25
    Last Post: 03-01-2011, 11:02 PM
  3. assignment help
    By esallender in forum New To Java
    Replies: 4
    Last Post: 10-25-2010, 12:10 PM
  4. First Assignment and already stuck....Newbie Question
    By Danieldcc in forum New To Java
    Replies: 5
    Last Post: 09-24-2010, 11:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •