Java Using Eclipse Beginner

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • corky20
    New Member
    • Dec 2006
    • 11

    Java Using Eclipse Beginner

    A series of transactions is to be made on a persons bank account. Each transaction will consist of a transaction type, either L for lodgements or W for withdrawals and an amount.

    e.g. L 55.00 Lodging 55.00
    W 30.00 Withdrawal 30.00

    It is not known how many transactions there are but the transactions are terminated by transaction type ‘X’.

    (i)Design and write a program to accept a person’s account number, their balance and a series of transactions.

    The final output from your program should be similar to the following:


    Account Number : 6578390

    Old balance : 103.00

    New balance: 234.00
    Last edited by Niheel; Dec 12 '06, 09:39 PM.
  • mharrison
    New Member
    • Nov 2006
    • 26

    #2
    You'd normally not find anyone here who will write the program you are looking for without first attempting a solution. As your new to java, what thoughts have you got on this problem?

    An initial thought could be that you could have a class to represent a Bank. From this, you could initiate a transaction to access an account, and since you know what type of transactions you will have: W, L or X,

    this part should be fairly straight-forward.

    Post a reply, and I'll be happy to help further.

    mharrison

    Comment

    • corky20
      New Member
      • Dec 2006
      • 11

      #3
      All my java work is in college at the minute!
      I've onli started java this year and this is the last example that i have to do before i get my first assignment. ive got it done but its not working and ive tried everything to get the friggin thing to work.
      I'm wondering if someone can help me re-write the code for this exmaple so i can move onto my first assignment nowing how to do everything and in school this website is blocked "which sucks"

      Thanks!!
      Last edited by corky20; Dec 7 '06, 08:44 PM. Reason: Adding stuff

      Comment

      • corky20
        New Member
        • Dec 2006
        • 11

        #4
        Originally posted by corky20
        All my java work is in college at the minute!
        I've onli started java this year and this is the last example that i have to do before i get my first assignment. ive got it done but its not working and ive tried everything to get the friggin thing to work.
        I'm wondering if someone can help me re-write the code for this exmaple so i can move onto my first assignment nowing how to do everything and in school this website is blocked "which sucks"

        Thanks!!
        If you think im don't know java this was the first example i done.

        public class excercise {

        /**
        * @param args
        */
        public static void main(String[] args) {
        // TODO Auto-generated method stub

        int postivetotal = 0;
        int negativetotal = 0;
        int number;
        final int TERMINATOR = 0;

        System.out.prin t ("Enter a number");
        System.out.flus h();
        number = uuInOut.ReadInt ();

        while (number != TERMINATOR){

        if(number > 0)
        postivetotal = (postivetotal + number);
        else
        negativetotal = (negativetotal + number);

        System.out.prin t ("Enter a number");
        System.out.flus h();
        number = uuInOut.ReadInt ();
        }

        }

        Comment

        • mharrison
          New Member
          • Nov 2006
          • 26

          #5
          Is this the code for the exercise you can't do? If it isn't (which I'm assuming is the case) then post what you have of the code you have done, and we'll take a look.

          mharrison

          Comment

          • corky20
            New Member
            • Dec 2006
            • 11

            #6
            Ok i urgently need the code for that question i posted if someone can please help me! basically i get of school for xmas on friday and i want to have all my java work done before i get off.
            If someone has the code i would much appreciate it...please!!!

            Comment

            • sicarie
              Recognized Expert Specialist
              • Nov 2006
              • 4677

              #7
              Originally posted by corky20
              Ok i urgently need the code for that question i posted if someone can please help me! basically i get of school for xmas on friday and i want to have all my java work done before i get off.
              If someone has the code i would much appreciate it...please!!!
              corky20-

              We're more than willing to help, but you have to meet us halfway. You posted code, but you didn't ask any questions, and it didn't look like the code did your assignment, or too much close - I suppose you have a while loop in there, but we see no variables like your teacher gave (int accountBalance, String inputLine, int oldBalance, int newBalance - for example) and there are no controls. You're not getting an entire line - as dictated by the example you provided - and you're not trying to parse that line to perform whatever addition or subtraction functions. To us, that looks like you didn't really try (especially when you ignore the advice left for you by mharrison 4 days ago and just ask for the code again).

              Now I say that and realize it sounds pretty harsh, but I'm just telling you what we see. What we need from you is:

              1) a specific question - such as how to read in the line from the user, or how to parse that line for the desired input
              2) the code you have already worked on to try to accomplish the question you ask
              3) the error messages you got from that code when you attempted to compile it

              If you do those 3 things, you will probably get 3 or 4 people commenting and trying to help.

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by corky20
                Ok i urgently need the code for that question i posted if someone can please help me! basically i get of school for xmas on friday and i want to have all my java work done before i get off.
                If someone has the code i would much appreciate it...please!!!
                I also vote that you post your code first.

                Comment

                • mharrison
                  New Member
                  • Nov 2006
                  • 26

                  #9
                  sicarie, you have my vote on this one too. If you post some code, you will get a much better response.

                  Comment

                  • corky20
                    New Member
                    • Dec 2006
                    • 11

                    #10
                    Ok since i didnt get to read any of them posts cause of maintence work i just have a small problem now.
                    When i enter the account number it lets me enter any size of number but i want it to only let me enter in a 7 digit account number. Any help!!!!!!

                    Code:

                    public static void main(String[] args) {

                    int accountNumber;
                    double oldBalance = 0;
                    double newBalance = 0;
                    double lodgement, withdrawal;
                    char transactionType = 'L' | 'W';
                    final char TERMINATOR = ('X');


                    System.out.prin tln("Enter seven digit account number: ");
                    accountNumber=u uInOut.ReadInt( );

                    System.out.prin tln("Enter transactionType : ");
                    transactionType =uuInOut.ReadCh ar();
                    uuInOut.ReadLn( );


                    while (transactionTyp e != TERMINATOR)
                    {
                    if (transactionTyp e == 'L'){
                    System.out.prin tln("Enter Amount to lodge: ");
                    lodgement=uuInO ut.ReadDouble() ;
                    newBalance = newBalance + lodgement;

                    }
                    else if (transactionTyp e == 'W'){
                    System.out.prin tln("Enter Amount to withdraw: ");
                    withdrawal=uuIn Out.ReadDouble( );

                    newBalance = newBalance - withdrawal;
                    }
                    {
                    System.out.flus h();
                    System.out.prin tln("Enter transactionType : ");
                    transactionType =uuInOut.ReadCh ar();
                    uuInOut.ReadLn( );
                    }

                    System.out.prin tln("Account Number :" + accountNumber + "\n");
                    System.out.prin tln("Old Balance:£" + uuInOut.Format( oldBalance,2)+ "\n");
                    System.out.prin tln("New Balance:£" + uuInOut.Format( newBalance,2)+ "\n");
                    }


                    }
                    }

                    Comment

                    • sicarie
                      Recognized Expert Specialist
                      • Nov 2006
                      • 4677

                      #11
                      Originally posted by corky20
                      Ok since i didnt get to read any of them posts cause of maintence work i just have a small problem now.
                      When i enter the account number it lets me enter any size of number but i want it to only let me enter in a 7 digit account number. Any help!!!!!!

                      Code:
                      public static void main(String[] args) {
                      
                      	int accountNumber;
                      	double oldBalance = 0;
                      	double newBalance = 0;
                      	double lodgement, withdrawal;
                      	char transactionType = 'L' | 'W';
                      	final char TERMINATOR = ('X');
                      	
                      	
                      		System.out.println("Enter seven digit account number: ");
                      		accountNumber=uuInOut.ReadInt();
                      		
                      		System.out.println("Enter transactionType: ");
                      		transactionType=uuInOut.ReadChar();
                      		uuInOut.ReadLn();
                      	
                      	
                      	while (transactionType != TERMINATOR)
                      	{
                      		if (transactionType == 'L'){
                      			System.out.println("Enter Amount to lodge: ");
                      			lodgement=uuInOut.ReadDouble();
                      			newBalance = newBalance + lodgement;
                      	
                      		}
                      		else if (transactionType == 'W'){
                      			System.out.println("Enter Amount to withdraw: ");
                      			withdrawal=uuInOut.ReadDouble();
                      			
                      			newBalance = newBalance - withdrawal;
                      	}
                      	{
                      		System.out.flush();
                      		System.out.println("Enter transactionType: ");
                      		transactionType=uuInOut.ReadChar();
                      		uuInOut.ReadLn();
                      	}
                      	
                      	System.out.println("Account Number :" + accountNumber + "\n");
                      	System.out.println("Old Balance:£" + uuInOut.Format(oldBalance,2)+ "\n");
                      	System.out.println("New Balance:£" + uuInOut.Format(newBalance,2)+ "\n");
                      	}
                      
                      
                      }
                      }
                      I would recommend putting your "Please enter a 7-digit number...." and your readIn statement in a while loop. Then you can have the test be that the account number is greater than 1000000 and less than 9999999. (just make sure that the condition is initialized to something that is not true so it enters into the while loop - or you do it once, and then have an if statement that contains the while loop, but the only get there if they put in an incorrect amount, etc... whichever way you want.)

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        Originally posted by sicarie
                        I would recommend putting your "Please enter a 7-digit number...." and your readIn statement in a while loop. Then you can have the test be that the account number is greater than 1000000 and less than 9999999. (just make sure that the condition is initialized to something that is not true so it enters into the while loop - or you do it once, and then have an if statement that contains the while loop, but the only get there if they put in an incorrect amount, etc... whichever way you want.)
                        Remember you are testing 2 things.
                        1. It has to be a number(Might need exception handling here)
                        2. It has to be 7 digits(String's length will do)

                        The best way however will be to use regular expressions

                        Comment

                        • corky20
                          New Member
                          • Dec 2006
                          • 11

                          #13
                          Thanks guy's i think i get what your saying!
                          I'll have ago and get back to you's if something goes wrong or something isn't working.

                          Comment

                          • r035198x
                            MVP
                            • Sep 2006
                            • 13225

                            #14
                            Originally posted by corky20
                            Thanks guy's i think i get what your saying!
                            I'll have ago and get back to you's if something goes wrong or something isn't working.
                            Sorry we might have appeared to be rude at the start but I think you'll learn more this way than if had simply given you the code

                            Comment

                            • sicarie
                              Recognized Expert Specialist
                              • Nov 2006
                              • 4677

                              #15
                              Originally posted by r035198x
                              Sorry we might have appeared to be rude at the start but I think you'll learn more this way than if had simply given you the code
                              And we'll be more than willing to help if you have trouble with that implementation or any future programs.

                              Comment

                              Working...