COMSATS University Islamabad Sahiwal Campus: (Computer Science)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

COMSATS University Islamabad Sahiwal Campus

(Computer Science)

Course Title: Object Oriented Programming Course Code: CSC241 Credit Hours: 4
Course Instructor: M. Usman Ali Programme Name: BS (CS) + BS (SE)
Semester: 2nd Batch: Section: A+B Date: 20/08/2020
Time Allowed: 3 Hours Maximum Marks: 50
Student’s Name: Reg. No. CIIT/ /SWL
Important Instructions / Guidelines:
Read the question paper carefully and answer the questions according to their statements.
Mobile phones are not allowed. Calculators must not have any data/equations etc. in their memory.
Terminal Examination Spring 2020

Question #1 [10 Marks]

In ocean navigation, locations are measured in degrees and minutes of latitude and longitude. Thus if you’re
lying off the mouth of Papeete Harbor in Tahiti, your location is 149 degrees 34.8 minutes west longitude, and
17 degrees 31.5 minutes south latitude. This is written as 149°34.8’ W, 17°31.5’ S. There are 60 minutes in a
degree. (An older system also divided a minute into 60 seconds, but the modern approach is to use decimal
minutes instead.) Longitude is measured from 0 to 180 degrees, east or west from Greenwich, England, to the
international dateline in the Pacific. Latitude is measured from 0 to 90 degrees, north or south from the equator
to the poles. Create a Java class angle that includes three member variables: an int for degrees, a float for
minutes, and a char for the direction letter (N, S, E, or W). This class can hold either a latitude variable or a
longitude variable. Write method to obtain an angle value (in degrees and minutes) and a direction from the
user, and a second to display the angle value in 179°59.9’ E format. Also write a three-argument constructor.
Write a main() program that displays an angle initialized with the constructor, and then, within a loop, allows the
user to input any angle value, and then displays the value. You can use the hex character constant ‘\xF8’, which
usually prints a degree (°) symbol.

Question #2 [10 Marks]

The population standard deviation is a measure of the spread (variability) of the scores on a given variable and
is represented by: σ = sqrt [ Σ ( Xi – μ )2 / N ]. The symbol ‘σ’ represents the population standard deviation. The
term ‘sqrt’ used in this statistical formula denotes square root. The term ‘Σ ( Xi – μ )2’ used in the statistical
formula represents the sum of the squared deviations of the scores from their population mean. Your Java
program need to take input in Scanner and also in Swing. The input is according to your own choice and display
the standard deviation.

Note: You will be decided which structure will be used to perform this task i.e. Array OR Nested_if OR
Multiple if_else_if OR Switch.
Question #3 [10 Marks]

Imagine a publishing company that markets both book and audiocassette versions of its works. Create a class
publication that stores the title(a string) and price(type float) of a publication. From this class derive two classes:
book , which adds a page count (type int), and tape, which adds a playing time in minutes (type float). Each of
these classes should have a getdata() method to get its data from the user at the keyboard and putdata() method
to display its data. Write a Java main program to test the book and tape classes by creating instances of them,
asking user to fill in data with getdata(), and then displaying the data with putdata(). Start with the publication,
book, and tape classes. Add base class sales that hold an array of three floats so that it can record the Rupees
sales of a particular publication for the last three months. Include a getdata() Method to get three sales amounts
from the user, and a putdata() Method to display the sales figure. After the book and tape classes so they are
derived from both publication and sales. An object of class book or tape should input and output sales data
along with its other data. Write a Java main() method to creat book and a tape object and exercise their
input/output capabilities. You will be decided that what type of Inheritance will be used to perform this task. For
this problem statement, only one Java program you will be write or two Java programs you will be write. Also
use super keyword if necessary.

Question #4 [10 Marks]

Write Java Program that evaluate the following Series using this, super and static keywords and methods with
the help of Exception Handling.

x+1/x2+1/x3+1/x4+1/x7+1/x10+1/x15+1/x16 … 1/x79

Question #5 [10 Marks]

Imagine a tollbooth at a bridge. Cars passing by the booth are expected to pay a 50 Rs. Toll. Mostly they do,
but sometimes a car goes by without paying. The tollbooth keeps track of the number of cars that have gone
by, and of the total amount of money collected. Model this tollbooth with a class called tollbooth. The two states
are a type unsigned int to hold the total number of cars, and a type double to hold the total amount of money
collected. A constructor initializes both of these to 0. A method called payingCar() increments the total car and
adds 5 to the cash total. Another method called nopayCar(), increments the car total but adds nothing to the
cash total. Finally a method called display() displays the two totals. Make appropriate methods constant. Include
a program to test the class. This Java program should allow the user to push one key to count a paying car, and
another to count a nonpaying car. Pushing the Esc key should cause the program to print out the total cars and
total cash and then exit. Also use File Handling to read and write all data.

Good Luck!

You might also like