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.
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;
while(true)
{
try {
payee = JOptionPane.showInputDialog("Enter Payee");
if(payee.length() == 0)
{
break;
}
amount = JOptionPane.showInputDialog("Enter
Amount");
c1 = new Check(payee, theAmount);
checkNumber.add(s1);
} 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