0% found this document useful (0 votes)
25 views

CSCI133 - Programming II - Lab 4

بعض الأسئلة العمليات

Uploaded by

Sami Saad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

CSCI133 - Programming II - Lab 4

بعض الأسئلة العمليات

Uploaded by

Sami Saad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Fall 2024 Lab Exercise 4 CSCI133: Programming II

Due date: At the end of the lab period.

Question 1:
Which of the following program segments contains an error?

a) public final int ARRAY_SIZE = 5;


ARRAY_SIZE = 10;

b) public int b[] = new int [10];


for(int i = 0; i <= b.ength; i++)
i. b[i] = 1;

c) public int a[][] = {{1,2},{3,4}};


a[1,1] = 5;

d) All of the above

Question 2:
Consider these two classes:

public class Animal {


private int age;
private String name, color;

public Animal(int age, String name, String color) {


this.age = age;
this.color = color;
this.name = name;
}

public String toString() {


return "Animal: Name: " + this.name + ", Age: " +
this.age + ", Color: " + this.color;
}

public void setAge(int age) {


this.age = age; }

public void setName(String name) {


this.name = name; }

public void setColor(String color) {


this.color = color; }
}
public class House {
private String address;
private Animal animal;

public House(String address, Animal animal) {


this.address = address;
this.animal = animal;
}

public String toString() {


return "House: Address: " + this.address +
", Contains: " + this.animal;
}

public String getAddress() {


return this.address;
}

public Animal getAnimal() {


return this.animal;
}
}

What would be the output of:


public class Driver {
public static void main(String[] args) {
Animal a = new Animal(2, "Emma", "Red");
House h1 = new House("Montreal", a);
a.setAge(3);
a.setName("Liam");
a.setColor("White");
House h2 = new House("Toronto", a);
System.out.println(h1 + "\n" + h2);
}
}
_____________________________________________________________
Question 3:
A. Write a Student class which keeps track of grades and generates a final mark. You
should store:
a. The name of the student
b. 2 quiz scores, an array of int, between 0 and 50;
c. 1 midterm score, an int between 0 and 100;
d. 1 final score, an int between 0 and 100;
e. Create the appropriate constructors
f. Create the appropriate getters and setters methods.

B. The Student class should also include the method calculateOverAllScore()


where:
a. Quizzes are worth 15% of the grade.
b. Midterm is worth 35% of the grade.
c. Final is worth 50% of the grade

C. The Student class should also include the method finallLetterGrade() where:
a. 100 ~ 90 => A
b. 90 ~ 80 => B
c. 80 ~ 70 => C
d. 70 ~ 60 => D
e. 60 ~ 0 => F

D. Write a main method in a drive class that defines an array of 5 students and print
them sorted based on the final grade.

You might also like