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!