Question about my project
Hi,
I have a project about a cash for metals company.
I created 3 classes to begin with: a super class Customer and 2 subclasses that inherit from the superclass. Each customer has a unique id.
Now i have to create a class named Account which will contain an account number. My question is how do i tie the unique account number with the unique id. What strategy should i follow. Customers will have one account but can have multiple transactions and are created each time a customer is created?
Thanks for the help.
Re: Question about my project
1. What are your two classes (subclasses)?
2. Create an independent Account class and create it's object in your Customer class. In your Account class, create a method that will verify the uniquness of Account Number. Call it at new Customer creation.
Re: Question about my project
Hi Mr. 777,
I have Customer as super class, and i created PersonalCustomer and ComercialCustomer as subclasses that inherit from Customer.
I also have a class Client that contains the main and an ArrayList that stores customers.
Right now i am working on the Account class.
These are the requirements for it.
1) Create an account for each customer. An account will have an account number (long),
balance (double), date opened (calendar) using the current date/time, and interest rate
(double).
2) Accounts have a default balance of 0 (balances cannot be less than 0) and a rate of 3%.
3) Get methods should be created for each attribute.
4) Accounts have two methods: makeDeposit (returns void) and makeWithdrawal (returns actual
amount withdrawn from the account).
5) Note the account should be created when the customer is created.
This is what i have so far. Am i on the correct track?
Code :
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class Account
{
public static final double DEFAULT_ACCOUNT_BALANCE = 0;
public static final double DEFAULT_INTEREST_RATE = .03;
private static long aNumber;
private double balance;
Calendar cal1 = Calendar.getInstance();
public Account()//default
{
balance = DEFAULT_ACCOUNT_BALANCE;
}
public Account (long number, double balance)
{
aNumber = number;
this.balance = balance;
}
public static void setAccount (long number)
{
number = (long)(Math.random()*100000000);
aNumber = number;
}
public void setBalance(double aBalance)
{
balance = aBalance;
}
public double getBalance ()
{
return balance;
}
public long getANumber ()
{
return aNumber;
}
public int getDate()
{
return cal1.get(Calendar.YEAR) + cal1.get(Calendar.MONTH) + cal1.get(Calendar.DAY_OF_MONTH);
}
public String toString()
{
return getClass() + "\nAccount: " + aNumber + " balance: " + balance + " Date: " + cal1;
}
public void makeDeposit (double amount)
{
balance = balance + amount;
return;
}
public double makeWithdrawal(double wAmount)
{
return wAmount;
}
public static void newCustomer (ArrayList<Customer> customers)
{
for (int i = 0; i < customers.size(); i++)
{
}
}
}
Re: Question about my project
Why are your class variables static? Though it's not wrong but it is strongly discouraged coz it kills OOP major functionality.
Well, all seems right to me, but where is account number and where are you checking it for uniquness?