Here is a summary of my project.
I have a cash for metals company that has both personal and commercial customers.
Customers can alos acumulate interest if they keep their money with the company. Some customers are repeat customers, therefore i need a way to keep track of multiple transactions for a customer.

So far i created the supercalss Customer and subclasses PersonalCustomer and CommercialCustomer that inherit from the superclass. I won't post all the code here because is very very long.

Now i am working on the Account class where i have some trouble. I am still struggling on creating a unique account id for each customer. This is what i have so far, am i on the right track?:

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 double getRate()
	{
		return DEFAULT_INTEREST_RATE;
	}
	
	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++)
		{
			
		}
	}
}

Recommended Answers

All 11 Replies

struggling on creating a unique account id for each customer

What are the rules for defining an account id?
For example: first 3 letters of last name, year of birth, 6 digit,incrementing id number that starts at 1.

There is actually no, instruction on the id rules.
But i see from the sample output that both Customer ID and Account Number are the same (10 digit number).

*** ***
*** Welcome to Cash for Metals Calculator!!! ***
*** ***
1. Create Personal Customer
2. Create Commercial Customer
3. Record Transaction
4. Make Withdrawal
5. Display Customer
6. Display Customer Summary
7. Display Grand Summary
8. Exit

Please input your choice (1-8): 5

Enter the customer ID to view a summary > 5642115654
Customer Name: Michael
Customer ID: 5642115654
Customer Address: 1 Avenue way

Account Number: 5642115654
Balance: $8900.00
Interest Rate: 0.03
Date Opened: 1/10/2011

Transaction ID: 5642115879
Gold Weight: 1.00
Platinum Weight: 1.00
Silver Weight: 1.00
Total Value: $9090.00

Home Phone: 111-111-1111
Work Phone: 111-111-1111


So this means that every time i create a customer i have to assign the same ID number to an account number. Do i have to create another ArrayList for the Acocunt numbers as well?

These are the Accoutn class requirments:
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%.
4. Get methods should be created for each attribute.
5. Accounts have two methods: makeDeposit (returns void) and makeWithdrawal (returns actual amount withdrawn from the account).
6. Note the account should be created when the customer is created.

There is actually no, instruction on the id rules

Then to have unique numbers, start with 1 and increment it by 1 for every new account.

I assume there is only one customer per account, or can there be co-owners?
Can a customer have more than one account?

There will be just one customer per account, and just one account per customer.

Will the customer id number be the same as the account id number?
Which will be assigned first? Customer or Account
If one is always first to get the number and the other always has the same number, you could copy the number from one that gets it first to the other one.

Specification does not say but i will make id num and acc num the same.
Also it says that accounts should be creted when customers are created,so customer id is first.

So if i create an object and then call the get id from customer like, ex:

static Customer customer1 = new Customer(name);

public static void setAccount (long number)
{
    aNumber = customer1.getIdNumber();
}

Would this work?

Would this work?

Write a small test program and see what happens.

Your posted code does not make sense.
Why is customer1 static?
What is done with the argument number that is passed to setAccount?
Why is setAccount static?
Where is the variable aNumber defined?

Can you explain what you want the code you posted to do?

getIdNumber() is the method that returns the customerID in class Customer.
So i wanted to assign that value to aNumber. This way both have the same value.

Your post talks about the one part of your code that I did NOT ask questions about.
What about the questions I did ask?

I am still working on those, otherwise i would have answered. As i am a begineer i have to go through the book, so it take a wile.

I explained what i wanted my code to do.

getIdNumber() is the method that returns the customerID in class Customer.

I don't see in your explanation of what you want the code to do, where you give the instance of the Customer class: customer1 its ID.

Your idea of using static is one way to generate ids, but the posted code is confusing & I don't see where it does what you want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.