nV News Forums

 
 

nV News Forums (http://www.nvnews.net/vbulletin/index.php)
-   Software Development (http://www.nvnews.net/vbulletin/forumdisplay.php?f=53)
-   -   Sigh, Java HW Help (http://www.nvnews.net/vbulletin/showthread.php?t=85029)

Marvel_us 01-25-07 05:12 PM

Sigh, Java HW Help
 
So basically I have to design a program that carries out banking operations on a customers' account.

Now what I need to do is create a class for the customers Name, Address, Bank Account, Customer and Bank database.

I'm having trouble with creating the class Customer. I want my constructor to accept a Name object, Address object and Bank Account object however I don't remember how to do that. The Name, Address and Bank Account classes are set up already.

This is what I have for the constructor but I'm stuck.

Quote:

public Customer( Name customerName, Address customerAddress, BankAccount customerBankAccount )
{
}
Did I set the constructor up right? If so, what the hell goes in the body?

Suggestions please.

rhink 01-25-07 06:09 PM

Re: Sigh, Java HW Help
 
Quote:

If so, what the hell goes in the body?
You probably want to store the objects you're passing in somewhere...

Marvel_us 01-25-07 06:19 PM

Re: Sigh, Java HW Help
 
So basically just declare variables of those types and assign them to the parameter variables in the body?

rhink 01-25-07 06:24 PM

Re: Sigh, Java HW Help
 
yup.

public class blah {
private SomeObject obj = null;

public blah(SomeObject input) {
obj = input;
}
}

Marvel_us 01-25-07 06:26 PM

Re: Sigh, Java HW Help
 
Ah thanks, I think I got it now.

Quote:

public class Customer
{
private Name name ;
private Address address ;
private BankAccount account ;

public Customer(Name n, Address add, BankAccount ba)
{
name = n;
address = add;
account = ba;
}
Correct?

Marvel_us 01-25-07 06:42 PM

Re: Sigh, Java HW Help
 
Another question...

All my classes compile, now it's time for a test class. The user will enter the information for each "customer". Would I just need to create one Customer object and then in the parameters create objects for name, address, account etc?

ie:

Customer cust1 = new Customer(new Name(args), new Addres(args), new BankAccount(args)) ;

Is that the best way to do it or does anyone have any suggestions?

Cinema4DXL 01-25-07 10:47 PM

Re: Sigh, Java HW Help
 
that wouldnt be the best way to do it. if your going to have a multiple customers, your going to need to create a list or array possibly to store each unique customer. the way you have it now everytime the user enters information it will recreate the cust1 Customer object (destory anything you previously entered)

but i cant be sure since i dont know the scope of your project

rhink 01-25-07 10:56 PM

Re: Sigh, Java HW Help
 
I agree, you probably want a single customer object per customer you have in memory, and store them in whatever your favorite type of list or collection is.

Marvel_us 01-25-07 10:56 PM

Re: Sigh, Java HW Help
 
Quote:

Originally Posted by Cinema4DXL
that wouldnt be the best way to do it. if your going to have a multiple customers, your going to need to create a list or array possibly to store each unique customer. the way you have it now everytime the user enters information it will recreate the cust1 Customer object (destory anything you previously entered)

but i cant be sure since i dont know the scope of your project

Thanks but I've actually got past that. I created an array to store the objects and looped the prompts so the user controls when they are done entering customers.

Problem I'm having now is how to print the array using jOptionPane.

Cinema4DXL 01-25-07 11:14 PM

Re: Sigh, Java HW Help
 
try converting what you want to output into a string and print the string into the jOptionPane

Marvel_us 01-25-07 11:16 PM

Re: Sigh, Java HW Help
 
Quote:

Originally Posted by Cinema4DXL
try converting what you want to output into a string and print the string into the jOptionPane

Makes sense, I'll give that a shot.

Thanks.

Tuork 01-25-07 11:25 PM

Re: Sigh, Java HW Help
 
I can actually hold my ground pretty well in Java.

What's your problem with JOptionPane?


All times are GMT -5. The time now is 11:50 PM.

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.