object oriented programming Assignments and quizzes, Assignments of Object Oriented Programming

this document based on assignment and quizes related to object oriented programming and its help student in their study

Typology: Assignments

2019/2020

Uploaded on 10/25/2020

mehwish-mehmood
mehwish-mehmood 🇵🇰

2.3

(3)

6 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Question No 1: Short Q/A [3 Marks]
1. For each of the statement in the left column write their correct answers in the right
column.
2. What are the benefits of data field encapsulation?
3. What is an accessor method? What is a mutator method? What are the naming conventions
for accessor methods and mutator methods?
4. . Suppose that s1, s2, s3, and s4 are four strings, given as follows:
5. What are the results of the following expressions?
SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY
BI0NFORMATICS DEPARTMENT
FALL 2019
OBJECT ORIENTED PROGRAMMING (CS-224)
Assignment 2
Semester: VI Batch: 2018
Due Date: 22-July-2019 Max Marks: 10
Instructions:
Attempt all questions
a. Specified in method that represent additional
information that method requires to perform its task
correctly.
b. Access Modifier to declare instance variables is a form
of information hiding.
c. Variables declared in the body of a particular method
and can be used only in that method.
d. Used in a class instance creation expression to create an
instance of a class.
e. Method that can be accessed outside of the class in
which it is declared.
f. Method that assigns a value to a private instance
variable.
g. Methods of the same name must have different sets of
parameters
h. Keyword that appears in declarations of constants.
i. If a method does not return a value, the return value
type must be?
j. It is used to call a constructor that parameter match
ANSWERS
a. _______________
b. _______________
c. _______________
d. _______________
e. _______________
f. _______________
g. _______________
h. _______________
i. _______________
j. _______________
String s1 = "Welcome to Java";
String s2 = s1;
String s3 = new String("Welcome to Java");
String s4 = "Welcome to Java";
pf3
pf4

Partial preview of the text

Download object oriented programming Assignments and quizzes and more Assignments Object Oriented Programming in PDF only on Docsity!

Question No 1: Short Q/A [3 Marks]

1. For each of the statement in the left column write their correct answers in the right

column.

2. What are the benefits of data field encapsulation?

3. What is an accessor method? What is a mutator method? What are the naming conventions

for accessor methods and mutator methods?

4.. Suppose that s1, s2, s3, and s4 are four strings, given as follows:

5. What are the results of the following expressions?

SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY

BI0NFORMATICS DEPARTMENT

FALL 2019

OBJECT ORIENTED PROGRAMMING (CS-224)

Assignment 2 Semester: VI Batch: 2018 Due Date: 22-July-2019 Max Marks: 10 Instructions:  Attempt all questions

a. Specified in method that represent additional

information that method requires to perform its task

correctly.

b. Access Modifier to declare instance variables is a form

of information hiding.

c. Variables declared in the body of a particular method

and can be used only in that method.

d. Used in a class instance creation expression to create an

instance of a class.

e. Method that can be accessed outside of the class in

which it is declared.

f. Method that assigns a value to a private instance

variable.

g. Methods of the same name must have different sets of

parameters

h. Keyword that appears in declarations of constants.

i. If a method does not return a value, the return value

type must be?

j. It is used to call a constructor that parameter match

ANSWERS

a. _______________

b. _______________

c. _______________

d. _______________

e. _______________

f. _______________

g. _______________

h. _______________

i. _______________

j. _______________

String s1 = "Welcome to Java"; String s2 = s1; String s3 = new String("Welcome to Java"); String s4 = "Welcome to Java";

What are the results of the following expressions?

6. Describe the role of this keyword.

Question No 2: Programming [7 Marks]

1. The atoms of different elements have different numbers of protons, neutrons and electrons. Electrons are negatively charged, protons are positively charged, and neutrons have no charge. a) In an object oriented programming language, write a definition for an Atom class that contains:  fields for storing the numbers of protons, neutrons and electrons with appropriate visibility;  setter and getter methods for manipulating these fields, ensuring that the minimum value for electrons and protons is 1, and the minimum value for neutrons is 0;  a constructor that initializes new objects of atom to be the smallest element (Hydrogen), for which the number of protons is 1, the number of neutrons is 0, and the number of electrons is 1. b) Write a new method for the atom class called isIon that will return true or false, depending upon whether the atom is an ion. An atom is an ion if it is charged (i.e., if the number of electrons ≠ the number of protons). c) Write a new method for the atom class called getAtomicMassNumber that will calculate and return the atomic mass number of the atom. Atomic mass number of an atom (often denoted A) is defined as the number of protons plus the number of neutrons. [3 Marks] 2. Imagine a tollbooth at a bridge. Cars passing by the booth are expected to pay a 50 cent 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. a. s1 == s b. s1 == s c. s1 == s d. s1.equals(s3) e. s1.equals(s4) f. "Welcome to Java".replace("Java", "HTML") g. s1.replace('o', 'T') h. s1.replaceAll("o", "T") i. s1.replaceFirst("o", "T") j. s1.toCharArray()

volume. The volume attribute will hold a number value representing the loudness (0 being no sound). The television object will also be able to control the state of its attributes. These controls become methods in our class. setChannel. The setChannel method will store the desired station in the channel field. power. The power method will toggle the power between on and off, changing the value stored in the powerOn field from true to false or from false to true. getChannel. The getChannel method will return the value stored in the channel field. getVolume. The getVolume method will return the value stored in the volume field. getBrand. method will return the constant value stored in the Brand field. getScreenSize. The getScreenSize method will return the constant value stored in the screensize field. Create a constructor definition that has two parameters, brand and a screen size. These parameters will bring in information You can only execute (run) a program that has a main method, so write a driver program.  Declare Television object called portable.  Instantiate portable to be a Sharp 19 inch television.  Use a call to the power method to turn the power on.  Use the suitable method to change the channel to 56.  Print out the values of brand , screensize and channel as output to your application [2 Marks]