Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-24-2007, 05:11 AM
zoe zoe is offline
Member
 
Join Date: Jul 2007
Posts: 40
zoe is on a distinguished road
Help with this code, overload the constructor
I have to write a program that returns an address and also three test scores. I need to provide a constructor that sets all instance values based on parameter values. I need to overload the constructor such that each test score is assumed to be initially zero and provide a method called setTestScore that accepts two Parameters: the test number 1-3 and the score, and a method called getTestScore that accepts the test number and returns the score.

Code:
public class StudentBody { private int value; public static void main (String[] args) { Address school = new Address ("800 Lancaster Ave.", "Villanova", "PA", 19085); Address jHome = new Address ("21 Jump Street", "Lynchburg", "VA", 24551); Student john = new Student ("John", "Smith", JHome, school);
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-25-2007, 09:17 PM
Member
 
Join Date: Jul 2007
Posts: 55
Seemster is on a distinguished road
public class Student() {
private Address home;
private Address work;
private Address school;
private int[] testScores = new int[] {0,0,0}

void Student(Address _home, Address _work, Address _school) {
this.home = _home;
this.work = _work;
this.school = = _school;
}

public int getTestScore(int testNo) {
return testScore[testNo];
}

public void setTestScore(int testNo, int testScore) {
testScore[testNo] = testScore;
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to decide whether to use Setter injection or constructor injection in your code Java Tip Java Tips 0 03-29-2008 01:38 PM
Calling constructor of parent class from a constructor Java Tip Java Tips 0 12-19-2007 10:10 AM
Calling constructor of same class from a constructor Java Tip Java Tips 0 12-19-2007 10:01 AM
How to decide whether to use Setter injection or constructor injection in your code JavaBean Java Tips 0 09-26-2007 09:29 PM
return type determines override/overload? hedefalk Advanced Java 4 07-11-2007 02:48 PM


All times are GMT +3. The time now is 03:08 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org