CSC 1302 Lab 6: Instance Field/Method solution

$24.99

Category:

Description

5/5 - (5 votes)

CSC 1302 Principles of Computer Science II
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. instance field :
i. teamName;
ii. NumberofWin;
iii. NumberofLoss;
b. Instance methods:
i. winAgame(): will increase the NumberofWin by 1
ii. lossAgame(): will increase the NumberofLoss by 1
2. Write a NBA class with main method to:
a. Create two teams: heat, laker
b. Generate a random number and if the number is bigger than 0.5, then heat wins;
otherwise lakers win
c. Do above step 3 times and then print out the win/loss of each team
3. Add the following methods to the NBATeam class and modify the main method in NBA
class to do the following:
a. setWinNum(n): will set the team’s NumberofWin to n
b. getWinNum(): will return the team’s NumberofWin
c. toString()
d. Create two teams: nets, warriors
e. Set the Number ofWin of each team to a random number between 1 and 82
f. Print out the win/loss of each team using toString()
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.