• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

New to Java - i need help please!

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm pretty new to Java, and have been given this problem to solve. I'm just finding it difficult to get started, so was wondering if anyone could give me some help to get the ball rolling. Lots of thanks in advance!

Here's my task -

A bank requires software to deal with customer accounts. In particular, it should keep a record of transactions that are carried out, adjusting the balance of the account accordingly.

The software should carry out the following:

1. Permit the user to enter the relevant details for up to 100 transactions for a given bank account. (In each case the user should be prompted for the date, amount of money for the transaction, and whether it was a withdrawal or a deposit.)

2. Adjust the balance after each transaction depending on whether it was a withdrawal or deposit. (These are the only two types of transactions to be considered.)

3. Print out a bank statement in the following format:

******************************************
Name: Tom White
Account Number: 89475020
Current Balance: 200.00OD
******************************************
Transactions
28/12/2005 1500.00 1500.00 D
1/1/2006 550.00 950.00 W
14/1/2006 50.00 1000.00 D
18/1/2006 1200.00 200.00OD W
******************************************

(Note that the number appearing after the date is the amount for the transaction, the next number is the resulting balance with OD for overdrawn and W and D for withdrawal and deposit respectively.)

You should write a class BankAccount, which will have relevant properties for an account including an array of instances of the class Transaction, as well as an appropriate constructor and methods. The methods should include methods for depositing or withdrawing money (see notes); an addTransaction method to add a new instance to the array, read in its details (including date, etc.) and update the balance using the deposit or withdraw methods; a printStatement method to give a printout as indicated above.

You should write an application program which makes use of the above classes. Since it is only used for testing the other classes only a single instance of BankAccount needs to be created. The user should be allowed to add as many transactions as required (up to 100). Finally, it should print out the statement.

Writing the class bankAccount ^^ and Application program ^^ are what are giving me trouble. Can anyone help? Thanks!
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have trouble writing the class? i assume you dont know how to do any of it then?

The class bank account will store your methods, addTransaction etc. And the application will be used to test them.





Thats what i think is meant.

[ April 02, 2006: Message edited by: Stephen Foy ]
[ April 02, 2006: Message edited by: Stephen Foy ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joe, what's your comfort level with what Stephen suggested there? Is that starting at the right level for you?

I'm going to suggest a way to approach such a problem on the ranch or with a mentor. I'm sure your first reaction will be that it will never work and you need an answer faster than this will get it for you. Trust us a bit and give it a try.

OK, I'm looking for the smallest thing in this program that we can write and test. And I think it's so small your instructor didn't even mention it, or maybe didn't think of it - a single Transaction. See if you can make this code run and say "true" three times:

Take a shot at it and post some code. Even if you feel hopelessly stuck that's the best way for us to see just what kind of help you need and get you moving. This can be a lot of fun!

By the way ... if you're feeling tempted to start with prompting the user and reading input, don't give in! With that approach you have to type test data over and over. By 2:00 AM you'll be really tired of typing. This way you put it into JoesTest once and never type it again. We can build the user input part of the program LAST and it will be a piece of cake by then.
 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This reminds me of program in the book, Java - How to program, is that your reading text book?
 
Joe Grimp
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aditionally, i've also been given some unfinished code and asked to complete it. This consists of two classes - the ClassDate and the ClassTransaction.

ClassDate code -

class Date
{// properties
private int day, month, year;

public Date (Date d) {
day = d.day;
month = d.month;
year = d.year;
}

public Date () {
}

// methods
public void readDate(){

//TO BE COMPLETED

}//readDate

public void printDate() {
System.out.print(day + "/" + month + "/" + year);
}//printDate

public boolean validDate()
{if (!validYear(year))
return false;
else if (!validMonth(month))
return false;
else if(!validDay(day,month))
return false;
else
return true;
}//validDate

private boolean validYear(int y)
{if ((y < 1990) || (y > 2100))
return false;
else
return true;
}//validYear

private boolean validMonth(int m)
{if ((m < 0) || (m > 12))
return false;
else
return true;
}//validMonth

private boolean validDay(int d, int m)
{if ((d < 0) || (d > daysinMonth(m)))
return false;
else
return true;
}//validDay

private int daysinMonth(int m)
{int NumDays;
switch(m)
{case 1:case 3:case 5:case 7:
case 8:case 10:case 12 : NumDays = 31;
break;
case 4:case 6:case 9:case 11:
NumDays = 30;
break;
case 2 : NumDays = 28;
break;
default: NumDays = 0;
}
return NumDays;
}//daysinMonth


} // end of class Date

The readDate method should prompt the user and read in relevant values for day, month and year and should determine whether the dates are valid by calling the method validDate.

Any ideas on how i can complete this code ^^^ ?


ClassTransaction code -

class Transaction {

private double amount;
private double newBalance;
private boolean type;
private Date d;

public void readTransaction() {
char c;
d = new Date();
d.readDate();

do
{
System.out.print("Is this transaction a withdrawal or deposit? (W or D)
");
c = uuInOut.ReadChar();
uuInOut.ReadLn();

if (c != 'W' && c != 'w' && c != 'D' && c != 'd')
System.out.println("Invalid entry. Try again.");

}while (c != 'W' && c != 'w' && c != 'D' && c != 'd');

if (c == 'W' || c =='w')
type = true;
else
type = false;
System.out.print("Enter amount: ");
amount = uuInOut.ReadDouble();
}

public void printTransaction() {

//TO BE COMPLETED

}

public boolean getType() {
return type;
}

public double getAmount() {
return amount;
}

public void setBalance(double value) {
newBalance = value;
}
}

Complete the class Transaction, by providing code for the method printTransaction.

Again any help with finishing the above code?

Thanks alot again for any help you can provide!
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joe,

Stephan and Stan gave you a skeleton and plan to get started. Don't try to do parts of the assignment before you are ready. It will be overwhelming if you do -- and you probably won't learn anything.

Start from the skeleton, try something small. And if you have any questions, ask here.

Henry
 
Joe Grimp
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the classDate, i have got the following so far for what has to be completed. Could anyone tell me how this is looking -



And can anyone help me with calling the validDate method.. i don't know how! Thanks. (The classDate code is ^^^)
 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To call methods you create an object to call it.



Give the print transaction an attempt, and post it here, this way we can see what your struggling with.
[ April 03, 2006: Message edited by: Stephen Foy ]
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joe Grimp:
For the classDate, i have got the following so far for what has to be completed. Could anyone tell me how this is looking -

And can anyone help me with calling the validDate method.. i don't know how! Thanks. (The classDate code is ^^^)



Great... you got started...

But instead of us telling you how it is looking, you can tell us. Write a test class that calls your readDate() method, and print out the variables that it sets.

Does it look like it is working correctly? Are the variables set correctly?

Henry
 
Joe Grimp
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the printTransaction -



Any opinions?
 
Wanna see my flashlight? How about this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic