Mid Term Question 233 CSE1115 A MNK-1
Mid Term Question 233 CSE1115 A MNK-1
Q1: (a) Logarithms are mathematical functions of the form log b x which consists of two parts: base (int b) [3+3]
and argument (double x). The logarithmic value is calculated using the formula:
log e x
log b x=
log e b
where log e x can be evaluated by Java code as Math.log(x).
You have to write a class Logarithm and include the member variables b and x, different types of
constructors and a function myfunc() to evaluate log b x such that the Main generates the output
provided in the following table:
Page 1 of 4
} }
} }
Page 2 of 4
public void start() {
System.out.println("[Vehicle] The vehicle is starting.");
}
Q4: Think about your own startup Uthao which is a ride sharing program using Java. Now due to our [2+1.5
country’s rules and regulations, vehicles on your platform must abide by the speedLimit at 80 km/h. +1.5+1
(a) Create a class name Ride that contains an attribute speedLimit which ]
● Cannot get changed by its child classes
● Cannot get changed once assigned
● Will contain an Integer value
● Must be static
Each child of Ride (that is, Bike, Car and Microbus) will receive a penalty for exceeding the
speedLimit. All the child classes have the following
initial_speed and acceleration:
Bike: initial_speed 20 km/h , acceleration 2 km/h
Car: initial_speed 40 km/h, acceleration 10 km/h
Microbus: initial_speed 15 km/h, acceleration 5 km/h
Page 3 of 4
Now do the following tasks:
(b) Create a method named getHighestAccelerationTime() ( return type: double ) which will find out the
time needed for a ride to reach the speedLimit by using the formula : v=u+at
(c) Create a method named calculateFine( int hour ) (return type: double ) which will calculate the fine
for each vehicle by following the implementation below:
Bike: Base fine will be 50 TK and for each hour exceeding speedLimit, it will add an extra 100
TK
Car: Base fine will be 100 TK and for each hour exceeding speedLimit, it will add an extra 150
TK
Microbus: Total fine will be 3000 TK for just exceeding speedLimit.
(d) Find out the output of the following Code:
Q5: (a) Can you define an abstract method in a non-abstract class? Provide a reason for your answer. [1+1
(b) An abstract class cannot contain variables. Do you agree with the statement? Provide a reason for +
your answer. 2+1
+1]
Suppose that you are tasked with modeling a library system for various types of reading materials. You
will be working with books, magazines. Each type of reading material has different properties. Thus, you
are required to accomplish the following tasks:
(d) Create a subclass named Book that inherits from ReadingMaterial and
i. Add an additional private field named genre (String) to hold the genre of the book.
ii. Add a constructor that takes all parameters (title, author, year, genre) and sets them properly.
iii. Now override the “displayDetails()” method to display the details of the book, including its title,
author, year, and genre.
(e) Create a subclass named “Magazine” that inherits from ReadingMaterial and
i. Add an additional private field named issueNumber (int) to hold the issue number of the
magazine.
ii. Add a constructor that takes all parameters (title, author, year, issueNumber) and sets them
properly.
iii. Now override the “displayDetails()” method to display the details of the magazine, including its
title, author, year, and issue number.
Page 4 of 4