Docsity

Object Oriented Techniques for IT Problem Solving Midterm Exam | IT 206, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
IT 206
—
A01
Object Oriented Techniques for IT Problem Solving
M
id
t
er
m Exam
Student Fu
ll
Name: I Got You Bro
Student Gnumber:
Student Emai
l
:
This
is
a
c
l
osed
book,
c
l
osed
note
exam.
No
use
of
ca
l
culator
is
a
ll
owed
during
the
exam.
The
exam
is 25% of the fina
l
course grade. The tota
l
grade is 50.
1. What is the imp
l
ication of using methods as b
l
ack box? (2 points)
a)
The user needs to know how every externa
l
method is implemented.
b)
The
user
needs
to
know
the
input
parameters,
return
va
l
ue,
and
the
way
a
method
is
being implemented.
c)
The user just needs to know input parameters and return va
l
ue of a method.
d)
Al
l
of the above.
2. What is wrong with the following codes (short explanation), and which type of error
(compi
l
er
error, syntax exception, logical error) does it result in? how can you fix the errors (rewrite the code
in the correct way)? Note that the statements inside the body of methods can be changed, but
you
cannot remove the statements!
(12 points)
a) Public
int
addNumbers(int
x,
int
y){
int z =
x+y;
}
No return statement
b) Public void foo(int b){ if
(b=0) return
0;
System.out.print(b*b);
}
Else statement needed
pf3
pf4
pf5

Partial preview of the text

Download Object Oriented Techniques for IT Problem Solving Midterm Exam | IT 206 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

IT 206—A

Object Oriented Techniques for IT Problem Solving

Midterm Exam

Student Full Name: I Got You Bro Student Gnumber: Student Email: [email protected] This is a closed book, closed note exam. No use of calculator is allowed during the exam. The exam is 25 % of the final course grade. The total grade is 50.

  1. What is the implication of using methods as black box? ( 2 points) a) The user needs to know how every external method is implemented. b) The user needs to know the input parameters, return value, and the way a method is being implemented. c) The user just needs to know input parameters and return value of a method. d) All of the above.
  2. What is wrong with the following codes (short explanation), and which type of error (compiler error, syntax exception, logical error) does it result in? how can you fix the errors (rewrite the code in the correct way)? Note that the statements inside the body of methods can be changed, but you cannot remove the statements! ( 12 points) a) Public int addNumbers(int x, int y){ int z = x+y; } No return statement b) Public void foo(int b){ if (b=0) return 0; System.out.print(b*b); } Else statement needed

IT 206—A

Object Oriented Techniques for IT Problem Solving

Midterm Exam

c) Public void foo(int b, int c){ if(c<0) return; for (int b=0; b< 10 ; b++) c = c+b; System.out.println(c); } Else statement needed for the times when value is more then or equal to 0

  1. Explain information hiding, what is the benefit of using information hiding? Given short answer. ( 2 points) Prevent other programs and users from modifying your data. Private
  2. Which of the following concepts is presented in the following UML diagram in Figure 1? ( 1 point) a) Information hiding b) black box c) Inheritance d) all of the above
  3. Which description applies to a Default constructor? ( 1 point) a) it has at least one parameter and has the same name as the class. b) State information is known by the application at the object orientation time. c) It has no parameters. d) b and c

This is a hotel room reservation application. Customers are three types: 1 ) new customers, 2 ) returning customers, 3 ) gold customers. The room prices for new customers are 3 rd^ night free, for returning customers are 20 % off of every night, and for gold members is 30 % off. Use inheritance to model this (customer is the super class for firstTimeCustomer, returningCustomer, and goldMemberCustomer). The following fields and methods must be implemented for every customer of any type:

  • ‐Customer driver’s license number (a double number)
  • ‐balance (a double)
  • ‐tostring () : reports the amount of money a customer pays for her stay period, i.e. the balance.
  • ‐applyPromotion(): calculates the balance after applying the related promotion.
  • ‐ don’t forget to add needed Mutators and Accessors. You also have a class called Hotel with the following fields: name, numberOfRooms, numberOfAvailableRooms, numberOfOccupiedRooms, array customers. Implement the required methods accordingly. When the program is started, a new instance of class hotel – that is shared among all the customers—is created. The program should ask for the following information about the hotel:
  • ‐name
  • ‐number of rooms For simplicity, assume that all the rooms are similar and their price is the same (the default price = 100$). Once the hotel is created, the program should ask the customer-‐user their demand, using the following menu: a) checking in hotel b) checking out hotel c) exit. if the customer chooses a) , the program should ask for the following information:
  • ‐customer drivers license number
  • ‐customer type
  • ‐number of rooms
  • ‐days of stay if b) is selected, the program asks the following information:
  • ‐customer drivers license number when a customer checks in, first, the program checks if there are sufficient number of rooms in the hotel for the customer to be reserved. If so, a new object of the corresponding customer type is created and added to the customers array, the number of rooms reserved by the customer updates occupied hotel rooms, and tostring() method should be called to print the final balance of the customer. Conversely, when a customer checks out, the number of available rooms for the hotel should be updated, and the customer should be removed from the customer array.

Create the java code for the program using the same theme followed in the lecture. Note that the second menu must pop up every time for a new customer to interact with the application as long as the program is running. Provide the required Mutators and Accessors to communicate with the fields of classes from external classes. Hint: suppose that the maximum length of the customers array is 100 , and assume this is the upper bound for a hotel. Hint: to create an array of class ABCwith length 10 , you should use: ABC[] abcObj = new ABC[ 10 ];