CSC 208 PQ Solution
CSC 208 PQ Solution
ANS:
import java.util.Scanner;
switch (yearOfStudy) {
case 100:
totalAmountPaid += 1000;
break;
case 200:
totalAmountPaid += 2000;
break;
case 300:
totalAmountPaid += 3000;
break;
case 400:
totalAmountPaid += 4000;
break;
case 500:
totalAmountPaid += 5000;
break;
default:
System.out.println("Invalid year of study
entered.");
return;
}
System.out.println("The student from the " + department + "
department in " + yearOfStudy + " level will receive a prize of #" +
totalAmountPaid + ".");
input.close();
}
}
2. Write a Java program that reads the names and exam scores of 100
that wrote CSC 208 examination in 2020 and displays a list containing the
names of students, their scores in the courses, grade and at the end of
the list the total and average scores for all the students.
ANS
import java.util.Scanner;
totalScore += scores[i];
}
System.out.println("-------------------------------------------------------
");
System.out.println("Total score: " + totalScore);
System.out.println("Average score: " + averageScore);
input.close();
}
}
3. Write a Java program that has three functions: main, pos_value and
neg_value. The function main prompts the user for a floating-point
number and checks whether the number is negative or positive. If the
number is negative, main will invoke the function make_pos which
multiplies the number by itself and prints the result. If the number is
positive, main will invoke the function make_neg which multiplies the
number by itself, then by -1 and prints the result.
ANS
import java.util.Scanner;
if (number < 0) {
make_pos(number);
} else {
make_neg(number);
}
input.close();
}
4c. create a UML class diagram representing two objects students and
lecturers in an institution and show the interaction between the objects.
ANS
+----------------+ +----------------+
| Student | | Lecturer |
+----------------+ +----------------+
| -studentID: int| | -lecturerID: int|
| -name: String | | -name: String |
| -email: String | | -email: String |
+----------------+ +----------------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
v v
+----------------+ +----------------+
| CourseGrade | | CourseGrade |
+----------------+ +----------------+
| -studentID: int| | -lecturerID: int|
| -courseID: int | | -courseID: int |
| -grade: double | | -grade: double |
+----------------+ +----------------+