NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES-FAST
Karachi Campus
Assignment #02(CLO1 ,CLO2 & CLO3 based)
CS1002 Programming Fundamentals
Batch 2024
Instructions:
1. The submission for this assignment is March 28, 2025 and the submission will close at 11:30 pm.
2. TAs will also check for plagiarism as well so do your work.
3. Submit a pdf file only if you want your assignment to be checked on GCR.
Question A:Describe the keywords and operators studied from chapter 7 to chapter 8 during the lecture. Give an
example to support your answer for every situation. [ each 2.5 marks * 15 = 37.5 Marks ] }--------------------CLO2
1. static
2.final
3. var
4. ...val
5. extends
7. implements
8.abstract
9. public
10. private
11. protected
12. import
13.periods
14. dot operator
15. java.lang.*;
Question B[ 30 +20 marks]
Part-1
Evaluate the situation to write the java program: }---------------------------------------- CLO 3
Design a class VideoTape whose data members are private. The data members are labeled:
string Title is a program title, int Duration is the running time of the program in minutes,
double Size is the video size in GB's, string Created is a const data member of a class and it stores
created date and time, string Resolution is given in pixels, and string Classification of the
programme(Comedy, Drama, or Talk Show).
a. The default constructor of the class should initialize Title as "TITLE", Duration as 0, and Size is
5.02, Created is "2010-07-09,21:42:40", Resolution is "1920 X 1080 pixels", and
Classification is "CLASSIFICATION". A parameterized constructor (string Title, int Dur,
double Size, string Created, string Resolution, string Classification) should initialize VideoTape's data members
just make sure classification should be from a given range as given above. If the classification does not match
above mentioned program list, assign the right value using SetClassification().
b. Create a VT1 and VT2 objects with a given Title, Duration, Size, Created, Resolution, and Classification. Create
VT3 and copy VT1 data in it.
c. Implement the following functions:
. string getTitle(); - Return VideoTape's Title
ii. int getDuration(); - Return VideoTape's Duration
iii. void setDuration(int); Update VideoTape's Duration
iv. double getSize(); - Return VideoTape's Size
v. string getCreated(); - Return VideoTape's Created
vi. string getResolution(); - Return VideoTape's Resolution
vii. string getClassification(); - Return VideTape's classification
viii. void setClassification(string);
Part-2
Evaluate the situation below and implement the concept of inheritance and overloaded constructor .
A super class name LengthDetail is created with two attributes length and width with type float .
The default constructor is formed to initialize the length and width with -1
A parameterized constructor that takes arguments for the attributes.
Make a third constructor as a copy constructor as pass an object as a parameter of the superclass type .
In the super class, a method calculates the total perimeter of the shape. The name of the method is
premeiter_shape and have a return type float.
Now make a subclass of class LengthDetail is created with name trapezium that has its own two attributes with
type float a and b . And construct all three constructors for this class and use super keyword to access the
superclass constructor .
And also make method name total_length with return type float , inside the body of the method call the method of
superclass using super keyword in order to calculate the total perimeter of the objects .
In the demo class created three objects of subclass Obj1 in initialized using the default constructor, Obj2 is
initialized using the second constructor in which the following lengths are passed:
length = 5.5 cm , width =7.56 cm , a= 3.45 cm and b = 1.50 cm
and a third object is created takes the attributes of Obj2.
In the demo class call methods to calculate the perimeter of all three objects and display all values using println
command .
Question C: {each 3*10 = 30 marks}---------------------------------------- CLO1
Write single-line short answers to the following questions:
a. If we add a parameterized constructor, then there is no need for a setter function. D o you agree with this? explain.
b. Why do we need to add a DEFAULT constructor, if it does nothing?
c. What happens if an attribute does not have a setter function?
d. A static function can be called using an object reference, so why is it recommended to use a class reference?
e. When do we want to declare a function as private?
f. What happens if a constructor is declared private?
g. How a superclass object can be referred to as a subclass object? Explain your answer with the help of a supporting
example.
h. Define the Complier-time and runtime polymorphism with an example.
i. How overriding of methods can be resolved .Explain it using appropriate example .