Module3A Assessment
Module3A Assessment
A. Theoretical Assessment Open your notes and read each item carefully. There are few items
that may have more than one answer. This is to test also your code reading skills. Mind your
work. (2 pts per ans.)
1. What will happen if you try to compile and run the following code?
public class MyClass {
2. What will happen if you try to compile and run the following code?
public class Q {
12. Which statements are most accurate regarding the following classes?
class A {
private int i;
protected int j;
}
class B extends A {
private int k;
protected int m;
// some methods omitted
}
A) In the class B, an instance method can only access k, m
B) In the class B, an instance method can only access i, j, k, m
C) In the class B, an instance method can only access j, m
D) In the class B, an instance method can only access j, k, m
13. What is displayed on the console when running the following program?
class Test {
public static void main(String[ ] args) {
try {
System.out.println(ʺWelcome to Javaʺ);
int i = 0;
int y = 2/i;
System.out.println(ʺWelcome to HTMLʺ);
}
finally {
System.out.println(ʺThe finally clause is executedʺ);
}
}
}
A. The program displays three lines: Welcome to Java, Welcome to HTML, The finally
clause is executed.
B. Welcome to Java.
14. Given:
class Plane {
static String s = "-";
public static void main(String[] args) {
new Plane().s1();
System.out.println(s);
}
void s1() {
try { s2(); }
catch (Exception e) { s += "c"; }
}
A. This code will not compile, because method doYourJob() in interface Guard must be
defined abstract
B. This code will not compile, because class Dog must implement method doYourJob()
from interface Guard
C. This code will not compile, because in the declaration of class Dog we must use the
keyword extends in stead of implements
D. This code will compile without any errors
class Person{
public void calculateSalary() throws SalaryCalculationException {
//...
throw new SalaryCalculationException();
//...
}
}
class Company{
public void paySalaries(){
new Person().calculateSalary();
}
}
Which of the following statements is correct? (2 answers)
A list of students with the averages of each based on the number of grades sorted in
descending order. Use old IO APIs and some arrays to implement the following project. All
averages must be in 2 decimal places with RoundingMode FLOOR.
2. For the next four problems, consider the task of representing types of tickets to school
campus events. Each ticket has a unique number and a price. There are three types of
tickets: walk-up tickets, advance tickets, and student advance tickets. Write a UML design
first and implement your design afterwards.
Walk-up tickets are purchased the day of the event and cost $50.
Advance tickets purchased 10 or more days before the event cost $30, and advance
tickets purchased fewer than 10 days before the event cost $40.
a) Implement a class named Ticket that will serve as the superclass for all
three types of tickets. Define all common operations in this class, and
specify all differing operations in such a way that every subclass must
implement them. No actual objects of type Ticket will be created: each
actual ticket will be an object of a subclass type. Define the following
operations:
The ability to construct a ticket by number.
The ability to ask for a ticket's price.
The ability to println a ticket object as a String. An example string
would be "Number: 17, Price: 50.0".
3.