CSC 1302 Principles of Computer Science II Lab 9: Object as Parameter

$30.00

Category: Tags: , , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (5 votes)

Purpose:
A class is a blueprint or prototype from which objects/instances are created. It includes fields or
methods that are common to all objects of the same blueprint/class. In general, a class
declaration has components: class header, constructors, methods such as getter/setter, and so on.
The constructors are used for initializing new instances. Fields are variables representing
the state of the class and its objects. The methods are used to implement the behavior of the class
and its objects.
In this lab, we will practice how to define classes and create objects. Once a class is
available, it’s like we have a new data type. Variables can be defined with a type of this class and
can refer to an object of this class. Methods can use this class as parameter type or return type.
Criteria:
1. Upload all of the .java and the .class files to the CSc1302 dropbox on http://
icollege.gsu.edu.
2. Your assignment will be graded based on the following criteria: (a) Are your programs
runnable without errors? (b) Do your programs complete the tasks with specified outputs?
(c) Do you follow the specified rules to define your methods and programs? (d) Do you
provide necessary comments include the programmer information, date, title of the
program and brief description of the program.
3. Please comment the important lines in the .java file as shown in the template. The
important lines including but not limited to i) variables, ii) for-loop, iii) while-loop, iv)
if-else statement, iv) methods. Please use your own words to describe what is your
purpose to write this line. A .java file without comment will be graded under a 40%
penalty.
4. Make sure that both the .java and .class files are named and uploaded to icollege
correctly. If any special package is used in the program, be sure to upload the package
too. Should you use any other subdirectory (whatsoever) your program would not be
graded, and you will receive a 0 (zero).
5. No copying allowed. If it is found that students copy from each other, all of these
programs will get 0.
Task:
1. Write a NBATeam class including the following components:
a. private field :
i. teamName;
ii. NumberofWin;
iii. NumberofLoss;
b. constructors:
i. NBATeam (String s, int w, int l)
c. methods:
i. winAgame();
ii. lossAgame()
2. Write a NBA class with main method to:
a. Create two teams: heat, spurs
b. Generate a random number and if the number is bigger than 0.5, then heat wins
over spurs; otherwise spurs win
c. Do above step 3 times and then print out the win/loss of each team
3. Modify a NBATeam Class to add the following method:
a. winAgame(NBATeam teamB)
b. lossAgame(NBATeam teamB)
4. Add toString() method to the NBATeam class and modify the main method in NBA class
to do the following:
a. Create two teams: heat, spurs
b. Generate a random number and if the number is bigger than 0.5, then heat wins
over spurs; otherwise spurs win
c. Do above step 3 times and then print out the win/loss of each team