Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds


  Asked By: Manju    Date: Mar 04    Category: Java    Views: 726

I have an assigmetn due next Wednsday and i am bit stock with the
vector part
The assigment ask to create three classes: Assign3, Check and
CheckExeption. Assign3 contains the main behavior.
Check is a class defining a check associated with a bank account.
The attributes of a check are amount, payee and check number.
CheckException is thrown by Check upon error conditions

The program tracks the checks for a single checking account. It
begins by asking the starting balance. Then it loops asking the user
for information (the payee and amount) about each check. If the
payee is empty, then the loop terminates and a report listing each
check in the account is produced.

I need to use a vector to hold the checks and i must use the Check
constructor to throw CheckExceptions when asked to create an invalid
Check numbers are automatically generated by the constructor.

I tried this for the Assign3 class:

import java.util.*;

import javax.swing.*;

public class Assign3

public static void main(String argv[])

Check c1;
Vector checkNumber = new Vector();
String amount;
String payee;
String checkNumber;
Amount theAmount = null;
int i;

try {
payee = JOptionPane.showInputDialog("Enter Payee");

if(payee.length() == 0)

amount = JOptionPane.showInputDialog("Enter

c1 = new Check(payee, theAmount);

} catch(NegativeAmountException e) {
JOptionPane.showMessageDialog(null, e, "Error!",

JOptionPane.PLAIN_MESSAGE, null);
System.out.println("Errors - quiting!");

for(i = 0; i < checkNumber.size(); i++)
c1 = (Payee) checkNumber.get(i);

System.out.println(c1 + "\n");

System.out.println("All done!");
And this for the check
public class Check

private String payee;
double amount;
private int CheckNumber;
private static int numberOfChecks = 0;

public Check (String p, double a) throws CheckException

payee = p;
amount = a;
CheckNumber = ++numberOfChecks;

if(amount.length() == 0)
throw new CheckException("Amount empty", this);

if(payee == null)
throw new CheckException("No payee", this);

public String toString()
return "Check = "+payee + "\n" + "amount = "+ amount
+"\n"+Check Number=+CheckNumber;


This is my CheckException
public class CheckException extends Exception {

private double amount;
private String payee;

public CheckException(double amount,String payee) {

super("negative amount");
this.amount = amount;
this.payee = payee;

If anyone can help or recomend any reference books or a forum group
for begginers i will be very grateful



1 Answer Found

Answer #1    Answered By: Terence Mitchell     Answered On: Mar 04

I will again recommend java  book from Deitel Associates, it has all
sort of sample code and projects one can find in real life. Check their
book it has sample bank account application. http://www.deitel.com

Didn't find what you were looking for? Find more on Vectors Or get search suggestion and latest updates.