Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Need Help With some Java Programming

  • 25-03-2009 12:49pm
    #1
    Registered Users, Registered Users 2 Posts: 79 ✭✭


    Hi Everyone,

    I'm abit stuck with this because i'm not 2 good with maths eventhou i'm told theres no maths in java which i belive there is but anyway I'm kind of lost and not sure what to put coz i think the 1000 has to go somewhere here.I'm generally lost with java and got some help off the net and other people.anyway heres what i have so far anyway.

    //Exercise1.java
    /*This program that attempts to simulate the actions of an ATM machine.*/
    import javax.swing.JOptionPane;
    public class Exercise1 {
    public static void main(String args[])
    {
    String menuText = "\n\n\t ********************ITT ATM************************\n\n\n\n\n\n\n\n "+
    "\n\n\tPlease choose from the following transactions types:\n\n\n\n\t "+
    " 'D' is Deposit\n\t 'W' is Withdrawal\n\t 'X' is Exit the System\n\n\n\n\t "+
    "Please enter your choice";

    String choiceAsString;
    char choice;
    float Deposit,Withdrawal,balance=1000;

    do{

    choiceAsString=JOptionPane.showInputDialog(menuText);

    while(!choiceAsString.equals("D") && !choiceAsString.equals("W") &&
    !choiceAsString.equals("X"))
    {
    choiceAsString = JOptionPane.showInputDialog("Invalid choice - please" +
    "re-enter\n\n" + menuText);
    }

    choice = choiceAsString.charAt(0);

    {
    case 'D':
    depositAsString = JOptionPane.showInputDialog("Please " +
    "enter the amount you wish to deposit");

    deposit = Float.parseFloat(depositAsString);

    balance = balance + deposit;
    JOptionPane.showMessageDialog(null,"Your Balance is now" +
    String.format("£%.2f");
    "ATM Balance",JOptionPane.PLAIN_MESSAGE);
    break;

    case 'W':

    withdrawalAsString = JOptionPane.showInputDialog("Please " +
    "enter the amount you wish to withdraw");

    withdrawal = Float.parseFloat(withdrawalAsString);



    }
    }




    }
    }


Comments

  • Closed Accounts Posts: 598 ✭✭✭IronMan


    Ah, the old ATM Java excercise, the memories of college assignments come flooding back. Next is the elevator simulation program, and the vending machine excercise.

    I won't help you with your homework. Sorry.


  • Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭Atomic Pineapple


    put the [code] attributes around your code to make it easier to read, is the code compiling or what is the problem?


  • Closed Accounts Posts: 92 ✭✭tpotter


    IronMan wrote: »
    Ah, the old ATM Java excercise, the memories of college assignments come flooding back. Next is the elevator simulation program, and the vending machine excercise.

    Lol, I think I still have one of the first generation Dietel "How to Program" books that followed a similar lesson plan. Timeless...


  • Registered Users, Registered Users 2 Posts: 2,534 ✭✭✭FruitLover


    Have you considered switching to a course more suited to your interests and abilities? Judging from your previous posts here, I don't think computer programming is really your kind of area....


  • Registered Users, Registered Users 2 Posts: 2,297 ✭✭✭Ri_Nollaig


    FruitLover wrote: »
    Have you considered switching to a course more suited to your interests and abilities? Judging from your previous posts here, I don't think computer programming is really your kind of area....
    what kind of thing is that to say!

    to the OP, can to repost using the
    tags as, and im giving you the benefit of the doubt here, your code is completely syntactically wrong...
    
    you missing keywords, like "switch" and looks like you are confusing while and do/while too.
    
    [code]
    switch(input) {
       case 1: // ...
               break;
       case 2: // ...
               break;
       default: //...
    }
    

    a switch statement should look like that ;)
    do {	
       choiceAsString = JOptionPane.showInputDialog(menuText);
       if(choiceAsString.equals("D")) {
          depositAsString = JOptionPane.showInputDialog("Please " + 
                                   "enter the amount you wish to deposit");
          try {
             deposit = Float.parseFloat(depositAsString);
          } catch (Exception e) {
             deposit = 0f;
             e.printStackTrace();
             // might want to look up exceptions ;)
          }
          balance += deposit;
          JOptionPane.showMessageDialog(null,"Your Balance is now " +
                             String.format("£%.2f",balance) + 
                             "ATM Balance",JOptionPane.PLAIN_MESSAGE);
       } else if (choiceAsString.equals("W")) {
           // ...
       } else {
           // invalid choice
       }
    } while (!choiceAsString.equals("X"));
    

    something like that might be better


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Ri_Nollaig wrote: »
    what kind of thing is that to say!

    Well she does say she got the code off the net and friends but does not how to add 1000 to it(?). Probably wants an answer rather then a way how to solve it.

    With a recession your probably better to study something to your strengths.

    The code looks like it was put together by someone who has no clue of Java. Or by a professor who is intentionally breaking the code so the person would go and solve it if they tried to cog from it.

    Here is what is wrong.
    1. your do loop makes no sense. Your while loop causes flickering (need to handle UI better)
    2. you have a number of variables not declared.
    3. messagedialog is broken.
    4. String.format ?
    5. Missing switch statement.
    6. Not using camelCase on variables.
    7. You are not factoring in nulls when the user hits cancel on your UI.
    8. Withdrawals code looks incomplete.


  • Registered Users, Registered Users 2 Posts: 2,534 ✭✭✭FruitLover


    Ri_Nollaig wrote: »
    what kind of thing is that to say!

    A much more patient and polite reply than the OP deserved, IMO. We've been through this several times before with this person, and they don't seem to be learning, nor making much of an effort to.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    OP have a read of this please.


This discussion has been closed.
Advertisement