Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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

  #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

Where have you got so far?

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

it's complicated!

everyone can go far!www.codeuu.com
  #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

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.

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

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