• Tidak ada hasil yang ditemukan

Exercise 1:

N/A
N/A
Protected

Academic year: 2025

Membagikan "Exercise 1:"

Copied!
4
0
0

Teks penuh

(1)

Name: Section: Fall 2010

ID: CSC113 MidTerm-2 Dr.

Question1: We want to manage the electricity charge invoice for buildings and villas.

We consider the following UML diagram:

<<Interface>>

Chargeable

+ electricityCharge()

FamilyBld - nbApartmenRooms : int + electricityCharge () SingleBld

- gender : char + ………..

Building

# name: String

# nbAppartment: int

+ electricityCharge ()

Villa …………..

+ electricityCharge ()

Apartment - id: String

- furnished : boolean - electCharge: double + …………..

(2)

The interface Chargeable contains the following method:

- electricityCharge( )

The class Building contains the following attributes and methods:

- name : name of the building

- nbAppartment: number of the apartments in the building.

- electricityCharge( )

The concrete class FamilyBld contains the following attributes and methods:

- nbApartmenRooms: number of rooms in the apartment.

- calculateCharge( )

This method returns the total electricity charge in family building using the following formula:

Total electricity charge of all apartments – discount amount.

Where discount amount is calculated as follows:

If the number of rooms is greater than 3 then discount amount will be 5% of the total electricity charge of all apartments.

Write in Java the interface Chargeable, the abstract class Building, and the concrete class FamilyBld .

Note: You can call getters and setters without implementation. Assume that the other classes are implemented.

(3)

Name: Section: Fall 2010

ID: CSC113 MidTerm-2 Dr.

Question 2:

We added the following methods to the class Building:

public void findAndStore(String filename, double amount)

This method stores in the file “building.data” all apartment objects having electricity charge less than amount.

public Apartment [ ] findFurnishedAndStore(String filename)

This method reads from the file “building.data and returns an array containing all furnished apartment objects.

Write in Java the two methods findAndStore and findFurnishedAndStore.

(4)

Name: Section: Fall 2010

ID: CSC113 MidTerm-2 Dr.

Question 3:

A. we assume that all apartments in a building are stored in a linked list.

Write a method to delete the apartment which consumes a high charge of electricity. ( Delete only first occurrence. Traverse the list only once).

B. Consider the following Java program. Trace and write the output of the program.

public class Test {

public static void main(String args[]) {

int numer[] = { 4, 8, 16, 32, 64, 128, 256, 512 };

int denom[] = { 2, 0, 4, 4, -1, 8 };

try {

for(int i=0; i<numer.length; i++) {

try {

System.out.println(numer[i] + " / " + denom[i] + " is " +numer[i]/denom[i]);

}

catch (ArithmeticException exc) {

System.out.println("Can't divide by Zero!");

} }

}catch (ArrayIndexOutOfBoundsException exc) {

System.out.println("Index out of bounds.");

System.out.println("Fatal error .");

} } }

Referensi

Dokumen terkait

A concise note (taking one minute!), written by students (individually or in groups), that focuses on a short question presented by. the instructor to the class, usually at the end

The results were a significant difference of critical thinking skills between control class and experiment class for elementary clarification: focus on a question (identifying

Amount with opinion above, but more broadly, cast about the dimen- sions according to the World Bank Capacity Building. According to the World Bank, in order to achieve the

• Students are able to answer the question of why, what, and where, as the result of their group discussion in a form of presentation in front of the class

In observation, this research asked to the teacher some question which divided into two categories. They are the general condition in English class especially in

About the students’ statements which represents the enjoyment of using Question and answer technique in speaking class, both show that there were 42.86% n=6 of 14 respondents who

The amount of question is 45 items that divided into 40 multiple choices and 5 essays.As for detail of items on cognitive domain in Indonesian subject i.e.the C1 level items at 11%

Ali Ahmed School and College Online Evaluation Questionsheet-1/ 2020 Time: 1.30 hour Class- 5; Subject- English Full marks: 50 Read the given text carefully and answer the