By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,470 Members | 1,907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,470 IT Pros & Developers. It's quick & easy.

Java Using Eclipse Beginner

P: 11
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
Dec 7 '06 #1
Share this Question
Share on Google+
15 Replies


P: 26
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
Dec 7 '06 #2

P: 11
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!!
Dec 7 '06 #3

P: 11
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.print ("Enter a number");
System.out.flush();
number = uuInOut.ReadInt();

while (number != TERMINATOR){

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

System.out.print ("Enter a number");
System.out.flush();
number = uuInOut.ReadInt();
}

}
Dec 7 '06 #4

P: 26
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
Dec 8 '06 #5

P: 11
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!!!
Dec 12 '06 #6

sicarie
Expert Mod 2.5K+
P: 4,677
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.
Dec 12 '06 #7

10K+
P: 13,264
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.
Dec 13 '06 #8

P: 26
sicarie, you have my vote on this one too. If you post some code, you will get a much better response.
Dec 14 '06 #9

P: 11
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");
}


}
}
Dec 14 '06 #10

sicarie
Expert Mod 2.5K+
P: 4,677
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!!!!!!

Expand|Select|Wrap|Line Numbers
  1.  
  2. public static void main(String[] args) {
  3.  
  4.     int accountNumber;
  5.     double oldBalance = 0;
  6.     double newBalance = 0;
  7.     double lodgement, withdrawal;
  8.     char transactionType = 'L' | 'W';
  9.     final char TERMINATOR = ('X');
  10.  
  11.  
  12.         System.out.println("Enter seven digit account number: ");
  13.         accountNumber=uuInOut.ReadInt();
  14.  
  15.         System.out.println("Enter transactionType: ");
  16.         transactionType=uuInOut.ReadChar();
  17.         uuInOut.ReadLn();
  18.  
  19.  
  20.     while (transactionType != TERMINATOR)
  21.     {
  22.         if (transactionType == 'L'){
  23.             System.out.println("Enter Amount to lodge: ");
  24.             lodgement=uuInOut.ReadDouble();
  25.             newBalance = newBalance + lodgement;
  26.  
  27.         }
  28.         else if (transactionType == 'W'){
  29.             System.out.println("Enter Amount to withdraw: ");
  30.             withdrawal=uuInOut.ReadDouble();
  31.  
  32.             newBalance = newBalance - withdrawal;
  33.     }
  34.     {
  35.         System.out.flush();
  36.         System.out.println("Enter transactionType: ");
  37.         transactionType=uuInOut.ReadChar();
  38.         uuInOut.ReadLn();
  39.     }
  40.  
  41.     System.out.println("Account Number :" + accountNumber + "\n");
  42.     System.out.println("Old Balance:£" + uuInOut.Format(oldBalance,2)+ "\n");
  43.     System.out.println("New Balance:£" + uuInOut.Format(newBalance,2)+ "\n");
  44.     }
  45.  
  46.  
  47. }
  48. }
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.)
Dec 14 '06 #11

10K+
P: 13,264
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
Dec 14 '06 #12

P: 11
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.
Dec 14 '06 #13

10K+
P: 13,264
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
Dec 14 '06 #14

sicarie
Expert Mod 2.5K+
P: 4,677
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.
Dec 14 '06 #15

P: 11
Cheers Guy's i seemed to be in a rush when i 1st asked bout this but i guess it is better this way rather than you giving me the code as i would learn nothing!

New Code:

public class AssignmentEg {

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();


if (accountNumber >9999999 && accountNumber <10000000){

System.out.println("Please enter current balance: ");
accountNumber=uuInOut.ReadInt();
System.out.println("*** Transaction Types***");
System.out.println("*** 'L' - Lodgement***");
System.out.println("*** 'W' - Withdrawal***");
System.out.println(("*** 'X' - Terminator***")+ "\n");
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("OldBalance:£"+uuInOut.Format(o ldBalance,2)+ "\n");
System.out.println("New Balance:£" + uuInOut.Format(newBalance,2)+ "\n");
}


}
}


Is there anyways to improve on this to make it easier to use or any cool things you can add which will make it that bit better??? i want to learn new things so any thing would be appreciated?!?
Dec 15 '06 #16

Post your reply

Sign in to post your reply or Sign up for a free account.