aspose file tools*
The moose likes Beginning Java and the fly likes Help!What is wrong with this program? (a simple bank account program) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help!What is wrong with this program? (a simple bank account program)" Watch "Help!What is wrong with this program? (a simple bank account program)" New topic
Author

Help!What is wrong with this program? (a simple bank account program)

akon johnsoon
Greenhorn

Joined: Apr 21, 2005
Posts: 2
hi there, my first post and i am already asking questions ; i am making a simple program which is supposed to stimulate a simple bank account (i am doing java programmin at university first year; that is why it is kind of simple; as i only did the course for 10 weeks ) ; anyway, here are the codes; and when i complie them i get 10 errors; i will only post the error messages at the end as they might help to solve my program problem;
The codes:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Bank extends Applet implements
ActionListener {


//this applet will use Account class to
//allow deposits & withdrawals

private TextField transField;//declare textfield
private int transaction;
private Account mybalance;

public void init() {
transField=new TextField(15);
add(transField);//add textfield to the
initialisation screen
transField.addActionListener(this); //add action
listener

mybalance = new Account (transaction); //introduce
new object
//mybalance
of the Account class
}

public void actionPerformed(ActionEvent event) {
if (event.getSource()==transField)

transaction=Integer.parseInt(transField.getText());
//assign value from textfield to a variable
//transaction



mybalance.creditOrDebit(transaction);//introduce
creditOrDebit method
//this
method will allow to add
//or
subtract values from balance
repaint();
}
public void paint (Graphics g) {
mybalance.display(g);

//this method will be responsible
//to keep the current balance on screen

}
}

class Account{ //class Account which generalises the
new object my balance
private int balance; //this balance is the actual
variable that keeps getting updated
public Account (int mybalance) { //setting up the
attributes for the constractor method
balance = mybalance;
}

public void creditOrDebit (int transaction) {
balance = balance + transaction;
}

public void display (Graphics g) {
//the display method with the decision whether to
draw in black or red

if(balance >= 0){
g.setColor(Color.BLACK);
g.drawString("YOUR ACCOUNT IS BALANCE � " +
balance, 50, 200);
}


else {
g.setColor(Color.RED);
g.drawString(" ACCOUNT OVERDRAWN � " +
balance, 50, 240);
}
}
}


The error messages:
Bank.java:18: ';' expected
initialisation screen
^

Bank.java:25: '(' or '[' expected
of the Account class
^

Bank.java:25: ';' expected
of the Account class
^
Bank.java:25: <identifier> expected
of the Account class
^
Bank.java:28: illegal start of expression
public void actionPerformed(ActionEvent event) {
^
Bank.java:51: ';' expected
}
^
Bank.java:55: illegal start of type
new object my balance
^
Bank.java:56: <identifier> expected
private int balance; //this balance is the actual
^
Bank.java:57: ';' expected
variable that keeps getting updated
^
Bank.java:84: '}' expected
}
^
10 errors

Process completed.


Thank you very much for reading my problem and i hope i get help!
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Always start with the first error. If your line wrap reflects the code accurately, you have comments continuing on the next line, which would cause that first error. In fact, several of your errors are directly caused by the line wrap, and some of the others are indirectly caused by the line wrap.

Also, please use the CODE UBB tags to enclose code. Doing so makes reading it much easier as it preserves the original formatting.
[ April 21, 2005: Message edited by: Jeff Bosch ]

Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
akon johnsoon
Greenhorn

Joined: Apr 21, 2005
Posts: 2
THANK YOU VERY MUCH; i did what you said and it worked; thank you; I LOVE THIS BOARD
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
You're welcome! I love it here too; that's why I play here so often...
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
For future reference, you should give us some indication what line causes the error. The error message tells us the line number, but few of us have the time to count the number of lines so it will help a lot if you just tell us which line it is instead.

Layne


Java API Documentation
The Java Tutorial
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Welcome to JavaRanch!

When you've completed the assignment, could you please run it on my bank account as it could use some stimulation!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help!What is wrong with this program? (a simple bank account program)