473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Help setting up a Class

PB
i have a class called school.java and i cant figure out how to construct
another class called course.java that adds 2 people to a course. Can anyone
help me out on how to set up constructors and such. Here is school.java

import java.text.DecimalFormat;

public class School
{
//-----------------------------------------------------------------
// Creates some Student objects, adds them to a course, and
// prints them.
//-----------------------------------------------------------------
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);
Student2 john = new Student2 ("John", "Smith", jHome, school,
75, 88, 78);

Address mHome = new Address ("123 Main Street", "Euclid", "OH",
44132);
Student2 marsha = new Student2 ("Marsha", "Jones", mHome, school,
100, 98, 94);

Course zoology = new Course("Zoology 101");
zoology.addStudent(john);
zoology.addStudent(marsha);

zoology.roll();

DecimalFormat formatter = new DecimalFormat("0.0#");
System.out.println();
System.out.println ("-------------------------------------");
System.out.print ("Overall Test Average: ");
System.out.println (formatter.format(zoology.average()));
}
}
Jul 17 '05 #1
1 1946
What you have is the correct way to do it.
If you want a ctor that takes N number of students.
You would probably want to create a Course ctor that takes a collection

public class Course {

public Course(List aCollectionOfStudents){

studentColl.addAll(aCollOfStudents);
}
private List studentColl = new ArrayList();

}

PB wrote:
i have a class called school.java and i cant figure out how to construct
another class called course.java that adds 2 people to a course. Can anyone
help me out on how to set up constructors and such. Here is school.java

import java.text.DecimalFormat;

public class School
{
//-----------------------------------------------------------------
// Creates some Student objects, adds them to a course, and
// prints them.
//-----------------------------------------------------------------
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);
Student2 john = new Student2 ("John", "Smith", jHome, school,
75, 88, 78);

Address mHome = new Address ("123 Main Street", "Euclid", "OH",
44132);
Student2 marsha = new Student2 ("Marsha", "Jones", mHome, school,
100, 98, 94);

Course zoology = new Course("Zoology 101");
zoology.addStudent(john);
zoology.addStudent(marsha);

zoology.roll();

DecimalFormat formatter = new DecimalFormat("0.0#");
System.out.println();
System.out.println ("-------------------------------------");
System.out.print ("Overall Test Average: ");
System.out.println (formatter.format(zoology.average()));
}
}


Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jagdeesh | last post by:
Hai Colleagues, I am using Tomcat 4.1.24 and JDK 1.4.0_03 in my winXP machine. I've transferred a set of folders(containing jsp files) into tomcat's webapps directory(to /webapps/bob ,...
3
by: Mike | last post by:
Hey guys I am pulling my hair out on this problem!!!!! Any help or ideas or comments on how to make this work I would be grateful! I have been working on this for the past 4 days and nothing I do...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: Carlo, MCP | last post by:
Hi, Sorry for posting twice, but I hope in your comprehension. Please help me! I'm troubling from months with a serious serialization problem that I'm not able to solve. I try to describe as...
5
by: Nmx | last post by:
Hi everyone, I'm writing a patch to a search engine (aspseek http://www.aspseek.org/) compile under gcc 3.4.4 on FC3. At some point, I found this piece of code: -- // Dirty hack to avoid...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: jgibbens | last post by:
First, thank you for even looking at my question. I am using VB 2005 and I have a question about XML. what I want to do is: 1. keep adding to this file with out over writing it 2. be able...
13
by: DDragon | last post by:
ok here is the problem, i have to forms which have values i wish to be added together i can add together the values in one form all right but im having problems with adding the values of the other...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.