Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 4th, 2007, 03:51 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please, could anyone help me with this exercise?

Develop a class with overloaded methods

1. Create a class called the Customer.java class

2. Within the customer.java class, create a method called setCustomerInfo and add an overloaded method setCustomerInfo

3. Depending on how the setCustomerInfo method is called, it does one of the following:

a. Sets the ID, name, address and phone no. for a Customer object (this is the minimum info. Needed for a new Customer)
b. Sets the ID, name, address, phone no., and email address for a Customer object.

4. Create a new test class called CustomerTest

5. In the main method:

a. Create 2 object references to different Customer objects
b. Use each variation of the setCustomerInfo method to provide information for each Customer object.
c. Display the contents of each Customer object.

Thank you so much

Reply With Quote
  #2 (permalink)  
Old December 5th, 2007, 10:19 AM
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Where have you got so far?

--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
Reply With Quote
  #3 (permalink)  
Old December 10th, 2007, 01:35 AM
yulin11
Guest
 
Posts: n/a
Default

it's complicated!

everyone can go far!www.codeuu.com
Reply With Quote
  #4 (permalink)  
Old December 10th, 2007, 12:19 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If I haven't got you wrong, I can say it is an easy task to accomplish. Of course, I can't write the whole class for you here, but I certainly can give you a hint.

Again if I haven't got you wrong, you got a problem with method overloading, which is not a problem at all. The idea behind overloading is that the programmer should have the freedom to group methods that have a similar, or sometimes the same function.

A method is distinguished from others by these attributes:
1) its name
2) its parameters
(I agree this is not clear enough, but this is not the place to be more verbose.)

Thus, you could create your overloaded method like this:
public void setCustomerInfo(Customer c, String newName, String newPhone){
c.name=new String(newName);
c.phone=new String(newPhone);
}
public void setCustomerInfo(Customer c, String newName, String newPhone, String newEmail){
c.name=new String(newName);
c.phone=new String(newPhone);
c.email=new String(newEmail);
}
I assume you have already defined relevant instance variables in your definition of class Customer. I believe this will compile perfectly well. Note that, although the names are the same, the signatures are different, which practically make these two separate methods.

I'm trying to make some amateur progress in Java myself, please forgive me my mistakes if there are any.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 Exercise 2 diango BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 4 February 1st, 2011 03:24 PM
Chapter 3 - Exercise 3 AndyN BOOK: Beginning Cryptography with Java 3 August 16th, 2006 03:09 PM
Exercise Solutions gsforfree BOOK: Beginning ASP.NET 1.0 3 June 28th, 2004 12:56 PM



All times are GMT -4. The time now is 05:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.