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.Decim alFormat;
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.addStud ent(john);
zoology.addStud ent(marsha);
zoology.roll();
DecimalFormat formatter = new DecimalFormat(" 0.0#");
System.out.prin tln();
System.out.prin tln ("-------------------------------------");
System.out.prin t ("Overall Test Average: ");
System.out.prin tln (formatter.form at(zoology.aver age()));
}
} 1 1957
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 aCollectionOfSt udents){
studentColl.add All(aCollOfStud ents);
}
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.Decim alFormat;
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.addStud ent(john); zoology.addStud ent(marsha);
zoology.roll();
DecimalFormat formatter = new DecimalFormat(" 0.0#"); System.out.prin tln(); System.out.prin tln ("-------------------------------------"); System.out.prin t ("Overall Test Average: "); System.out.prin tln (formatter.form at(zoology.aver age())); } }
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 , /webapps/sue) and i have added the
folders bob, sue in my server.xml(in the context path).
When i am trying to run jsp files from my browser, it works fine. But,
the following jsp files reports some exceptions which is quite hard to
understand. Here is...
|
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 seems to get me any closer to
the solution. Below is a program that I am working on for a class project.
The original code was provided for us which is what I have below. What we
have to do is make the app run so that it allows the user to add...
|
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
--------------------------------------------------------------------------------
Hello,
I have a very simple problem but cannot seem to figure it out. I have a
very simple php script that sends a test email to myself. When I debug
it in PHP designer, it works with no problems, I get the test email. If
|
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 simply
as I can.
1) I have a class tha does something with colors. All default values are
obviously NOT serializad. Instead, they are serialized when they are
|
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 non-threadsafeness of string class
// We set ref to big value here so it will not reach 0
| |
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 efficient
navigating within Visual Studio 2005. Let's say your project (or
solution) has dozens of forms and hundreds or even thousands of
routines.
Two Questions:
1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
|
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
********************************************************
For this teeny job, please refer to:
http://feeds.reddit.com/feed/8fu/?o=25
|
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 to change stuff the XML without overwriting the rest of the file
This is the XML I have:
|
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 form to it... ill post the code for you to look at and try to explaine in detail what im trying to do.
here is the code (HTML and Javascript so you get the whole picture):
Javascript:
var gen, lights;
var lammount;
|
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?
Why do I need to set a property within my code to the service name?
Are all these required or am I just doing this for consistency purposes?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |