0% found this document useful (0 votes)
150 views3 pages

Object Oriented Programming (Swe-103) Lab Exam: Stock Symbol Name Double Previousclosingprice Double Currentprice

This document contains instructions for a lab exam on Object Oriented Programming. It lists 7 questions, with question 7 being compulsory. The questions involve designing classes to represent stocks, fans, geometric figures, players, and automobiles. They also include writing a program to convert lengths between feet/inches and inches/centimeters, handling exceptions for invalid input.

Uploaded by

Ramsha Mahar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
150 views3 pages

Object Oriented Programming (Swe-103) Lab Exam: Stock Symbol Name Double Previousclosingprice Double Currentprice

This document contains instructions for a lab exam on Object Oriented Programming. It lists 7 questions, with question 7 being compulsory. The questions involve designing classes to represent stocks, fans, geometric figures, players, and automobiles. They also include writing a program to convert lengths between feet/inches and inches/centimeters, handling exceptions for invalid input.

Uploaded by

Ramsha Mahar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

Object Oriented Programming (SWE-103)

Lab Exam

Instructions:
• Attempt 2 questions where Question 7 is compulsory.
• The formula for getting next question is (Rollno%6)+1 or (Rollno
mod 6)+1 for example 123%6=3+1 (Attempt Question No 4)
126%6=0+1( Attempt Question No 1)
Question 1:

Design a class named Stock that contains:


■ A string data field named symbol for the stock’s symbol.
■ A string data field named name for the stock’s name.
■ A double data field named previousClosingPrice that stores the stock
price for the previous day.
■ A double data field named currentPrice that stores the stock price for the
current time.
■ A constructor that creates a stock with the specified symbol and name.
■ A method named getChangePercent() that returns the percentage
changed
from previousClosingPrice to currentPrice.
Write a test program that creates a Stock object with the stock symbol
ORCL, the name
Oracle Corporation, and the previous closing price of 34.5. Set a new
current
price to 34.35 and display the price-change percentage.
Question 2:
Design a class named Fan to represent a fan. The class contains:
■ Three constants named SLOW, MEDIUM, and FAST with the values 1,
2, and 3 to
denote the fan speed.
■ A private int data field named speed that specifies the speed of the fan
(the
default is SLOW).
■ A private boolean data field named on that specifies whether the fan is on
(the default is false).
■ A private double data field named radius that specifies the radius of the
fan(the default is 5).
■ A string data field named color that specifies the color of the fan (the
defaultis blue).
■ The accessor and mutator methods for all four data fields.
■ A no-arg constructor that creates a default fan.
■ A method named toString() that returns a string description for the fan. If
the fan is on, the method returns the fan speed, color, and radius in one
combined string. If the fan is not on, the method returns the fan color and
radius along with the string “fan is off” in one combined string.

Question 3:

Write a program that prompts the user to enter the length in feet and inches
and outputs the equivalent length in inches and in centimeters. If the user
enters a negative number or a nondigit number, throw and handle an
appropriate exception and display the message
Question 4:

Create an abstract class called GeometricFigure. Each figure includes a


height, a width, a figure type, and an area. Include an abstract method to
determine the area of the figure. Create two subclasses called Square and
Triangle. Create an application that demonstrates creating objects of both
subclasses, and store them in an array and display area.
Question 5:

Create an interface called Player. The interface has an abstract method


called play() that displays a message describing the meaning of “play” to
the class. Create classes called Child, Musician, and Actor that all
implement Player. Create an application that demonstrates the use of the
classes.
Question 6:

Create an abstract Auto class with fields for the car make and price. Include
get and set methods for these fields; the setPrice() method is abstract.
Create two subclasses for individual automobile makers (for example,
Ford or Chevy), and include appropriate setPrice() methods in each
subclass (for example, $20,000 or $22,000). Finally, write an application
that uses the Auto class and subclasses to display information about
different cars.
Question 7(Compulsory)

Write a program that prompts the user to enter the length in feet and inches
and outputs the equivalent length in inches and in centimeters. If the user
enters a negative number or a nondigit number, throw and handle an
appropriate exception and display the message

You might also like