G 76 Rfgyb
G 76 Rfgyb
Mid-Sem Exam
Total marks=106
Instructions:
o Any form of notes or electronic device not allowed.
o Your responses need to be specific, in terms justification.
o Make necessary assumptions. Ignore syntactic errors unless otherwise mentioned.
o For all questions, the minimum points is zero.
o Once you’re done you need to tag/attach/staple the answer (and supplementary) sheets
with the question paper and return them.
Time allowed: 60 minutes. Total: 100 points
1. [31] Writing a basic class
Marking scheme :Explanation of access modifiers , its scope and also
dataType-> full marks , else half
package ChessOlympiad;
public class ChessOlympiadTeam {
/** Question 1 (4 pts): Add fields for the following properties, which cannot be accessed
outside of the class. name of the team number of wins number of losses *
-2 if any field is not private * -2 if type of any field is wrong **/
/** Question 3 (5 pts): Write a second constructor that takes only the name of the team as an
argument. This constructor should set the name of the team to the argument and the set the
number of wins and losses to 0. This constructor should be accessible from any package* -1
missing public keyword *
-1 wrong parameter types or number * -2 for incorrect body **/
/** Question 4 (4 pts): Write methods that return the name of the team, the number of the wins,
and the number of losses. These methods should be accessible from any package. *
-2 if any method has wrong signature * -1 if any method missing * -1 for wrong body(s) **/
/** Question 5 (4 pts): Next write a method to increase the numbers of wins by 1 and another
method to increase the number of losses by one. These methods should only be accessible from
inside the ChessOlympiad package *
-2 if any method has wrong signature * -2 for wrong body(s) **/
void win()
{
wins++;
}
void lose()
{
losses++;
}
/** Question 6 (4 pts): Write a method that returns true when a team has a “good record,”
meaning the team has more wins than losses. This method should be accessible from any
package. *
-2 for wrong signature * -2 for wrong body **/
/** Question 7 (6 pts): Finally, add a main method to the ChessOlympiadTeam class. In the
main method, construct a ChessOlympiadTeam named "Chakra" with 3 wins and 5 losses. Call
the method that returns true when the team has a good record and print out the result. Now
make three calls to the method that increases the number of wins by 1. Lastly, call the "good
record" method again and print out the result.
* -2 for wrong signature * -4 maximum for failure to follow specifications **/
public static void main(String[] args) {
ChessOlympiadTeam chakra = new ChessOlympiadTeam("Chakra", 3, 5);
System.out.println(chakra.hasGoodRecord());
for (int i = 0; i < 3; i++)
chakra.win();
System.out.println(chakra.hasGoodRecord()); }
}
//Removes and returns the item from the head of the queue
public Object dequeue();
}
(10 pts) Write the output of the following commands or, if the program terminates abruptly, write
the name of the exception that is printed to the console:
Java Differential 18 9 answer: 2 [2.5 pts]
Java Differential 5 null answer: bad input [2.5 pts]
Java Differential 10 answer: division by zero
[2.5 pts]
Java Differential 4 answer: bad input 1 [2.5 pts]
Points distribution:
1. Student class with appropriate fields: [5pts]
2. Methods to initialize the in-memory data database (using collections): [10pts]
3. Methods to add new records (must use collections): [7.5pts]
4. Methods to search student records (must use collections): [7.5pts]
Student class with fields (name, roll number, cgpa) //if any of the field is missing then award 0
class Student
{
String name;
int rollNumber;
double cgpa;
}
OR
OR
OR
if (foundStudent[0] != null) {
System.out.println("Found using forEach(): " + foundStudent[0]);
} else {
System.out.println("Student with roll number " + rollNumber + " not found using
forEach().");
}
return foundStudent[0];
OR
//TREESET [It must be implemented using contains()]
public Student searchStudent(Student student) {
if (studentSet.contains(student)) {