



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The solutions for a csc 227 practice test, including the evaluation of various expressions and the writing of pass or fail assertions for junit tests. Additionally, it includes the code for a java program that tests student records and gpa calculations, as well as a unit test for a static method that returns letter grades based on percentage.
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!




int j = 5; int k = 3; double x = -1.5; double y = 2.3; String s = "Al Gore";
a) ____ 2 ___ j / k b) ____ 'r' ___ s.charAt(5) c) __ 2.0 ___ Math.sqrt(y + 1.7) d) __ 2 ___ Math.round(y) e) __ false _ x + 5.1 > y + 2. f) __ false _ (k > j) && (k < 3) g) ___ 2 _____ j % k h) ____ 2 ____ j + k / 4 i) false _ s.equals("AL GORE") // Missing " j) _ "AL GORE" _ s.toUpperCase() k) __ false __ true && false l) ___ -1 ___ s.indexOf("go");
// The long expression actually returns true
public class TestStudent { public static void main(String[] args) { Student aStudent = new Student("Yang Li"); Course one = new Course(3.0, 4.0); // a 3 unit A (As are 4.0) Course two = new Course(2.0, 3.0); // a 2 unit B (Bs are 3.0) System.out.println(one.getUnits()); System.out.println(one.getGrade()); aStudent.recordCourse(one); System.out.println(aStudent.getName() + "'s GPA is " + aStudent.getGPA()); aStudent.recordCourse(two); System.out.println(aStudent.getName() + "'s GPA is " + aStudent.getGPA()); } }
**3.
Yang Li's GPA is 4. Yang Li's GPA is 3. public class Course { private double my_units; private double my_grade; public Course(double units, double grade) { my_units = units; my_grade = grade; } public double getUnits() { return my_units; } public double getGrade() { return my_grade; } } public class Student { private String my_name; private double my_units; private double my_qualityPoints; public Student(String name) { my_name = name; my_units = 0.0; my_qualityPoints = 0.0; } public String getName() { return my_name; } public double getGPA() { return my_qualityPoints / my_units; } public void recordCourse(Course aCourse) { my_units = my_units + aCourse.getUnits(); my_qualityPoints = my_qualityPoints + (aCourse.getUnits() * aCourse.getGrade()); } }**
int j = 1; int n = 5; while(j <= n) { System.out.print("Hello"); n++; } INFINITE int j = 1; while(j <= 11) { System.out.print("Hello"); j = j + 3; } 4
int n1 = 10; int n2 = 1000; while(n1 * n1 <= n2) { System.out.println(n1 + " " + n2); n1 = n1 + 1; n2 = n2 - 200; }
10 1000 11 800 12 600 13 400 14 200 int n1 = 10; int n2 = 1000; while(n1 * n1 <= n2) { System.out.println(n1 + " " + n2); n1 = n1 + 1; n2 = n2 - 200; }
Histogram quizzes = new Histogram ( ); quizzes. addAndShowOne ( 7 ); quizzes.addAndShowOne( 8 ); quizzes.addAndShowOne( -1 ); quizzes.addAndShowOne( 11 ); quizzes.addAndShowOne( 10 ); quizzes.addAndShowOne( 0 ); quizzes.addAndShowOne( 5 ); quizzes.addAndShowOne( 9 ); System.out.println( ); System.out.println( "Average: " + quizzes. getAverage ( ));
-1 is out of range 11 is out of range ********** 10 0 ***** 5 ********* 9 Average: 6.