• 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

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
akon johnsoon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANK YOU VERY MUCH; i did what you said and it worked; thank you; I LOVE THIS BOARD
 
Jeff Bosch
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome! I love it here too; that's why I play here so often...
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

When you've completed the assignment, could you please run it on my bank account as it could use some stimulation!
reply
    Bookmark Topic Watch Topic
  • New Topic