Description
[Answer on answer script. at the beginning partl
abs tract class Shape { abstract double getArea ( ) ,
public class QI { public static void main (String ( ] args) {
Circle (2)
Shape circle = new
Shape rectangle = new Rectangle (5, 7) ,
System. out . printIn (“Area of the circle: “+circle . getArea() )
System. out . printIn (“Area of the rectangle : “+rectangle . getArea ( ) )
Page 1
Design the Rectangle and Circle classes so that the following output is printed when we run the class.
I-lint: Rectangle and Circle classes are child classes of Shape
Area of the circle: 12.56
Area of the rectangle: 35.0
Question 2 110 Pointsl CO 4
[Answer on answer script, at the beginning partl
Given the following classes, complete the code so that the following output IS printed when we run the Q2 class.
6.0
13.75
{
Write your code here
public
static void main (String [ ] args) {
System. out. printin (product (2 , 3) )
System. out . println (product (5 . 5 , 2 . 5) ) ;
public class Q2
Question 3 110 Points’ BONUS C08, C09
[Answer on answer script. at the beginning partl
Given the following classes, design the Motorbike class so that the following output is printed when we run the Q3 class
Note: Motorbike is to be designed based on the Bike interface.
Speed: 0
Speed: 60
Speed: 50
interface Bike {
void speedUp (int increment) •
void applyBrakes (int decrement) ,
public class Q3 { main (String [ ] args)
public static void
= new Motorbike ( ) ,
Motorbike mb mb . printStatus ( ) ,
mb . speedUp ( 60)
( ) ;
mb . printStatus applyBrakes (10)
mb .
mb . printStatus ( )
Page 2 4 SET-A
1+ 2 t g
m-f ,O’1n
uestion 4 10 Points co 4
publxc ciaos Per gon ( public void gendSMS ( ) {
System. out: . prxntln (this + “Person gendSMS ) gendEmaiI ( )
public void gendEmaiI ( )
System. out. println (this + t ‘ Person gendEmaiI ” ) publxc class PoatGradStudent extends
Student ( public void sendSMS ( ) ( super . sendSMS ( )
System. out. printin (this +
“Pog tGradStudent sendSMS
public void sendEmai1 ( )
Syotem. out. println (thig +
“PostGradStudent gendEmai1 i ‘ )
public void deposit.AIIowance ( )
System. out. println (this +
“PostGradStudent depositA110wance”) ;
publxc String toString() { return “Person: •
public class Staff extends Person ( public void sendSMS {
System. out. printin (thig + “Staff sendSMS”) •
public void sendEmaiI ( )
System. out. println (this + “Staff gendEmaiI t’ ) sendSMS ( ) ,
public String toString ( ) ( return “Staff :
public class S tudent extends Person ( public void sendEmai1 ( )
System. out. println (this + “Student sendEmai I ” )
public void deposi tA110wance ( )
System. out. ( this + “Student depositAIIowance”) ;
Assume that the following variables have been defined:
Person person 1 = new Student(); Person person2 = new PostGradStudent();
Student student 1 = new Student();
Student student2 = new PostGradStudent();
Staff staff 1 = new Staff();
Object objl = new Student();
Jn the table below, indicate in the right-hand column the output produced by the statement in the left-hand column. If the statement produces more than one line of output, indicate the line breaks with slashes as in “a/b/c” which indicates three lines of output with “a” followed by “b” followed by “c”. If the statement causes an error, write either “CT” for “compile time error” or RE for “runtime error” to indicate when the error would be detected.
Output (answer on question paper]
Statement stam.sendSMS()•
person I send Email();
person2.sendEmail();
studentI.sendEmail();
student2.sendEmail();
studentI.depositAllowance();
student2.depositAIlowance();
(PostGradStudent)staffl
((Student)person2).depositAlIowancc();
(( PostGradStudent)objI )send Email(),
Page 3 of 4 SET-A
n:cawvy
Question 5 [6 Points] COS _(answer on question paper)
class Parent (
publxc Child (Parent b) (
publxc void proc (int n, int m)
thx
q s . q; p = this. q + 2 + r;
•
super . proc (p, q) r = p + q + super. r;
System. out. printin (r +
Reviews
There are no reviews yet.