Homework 2 – v1 Solution

$30.00 $24.90

Description

Rule 1: no plagiarism (from colleagues or other sources). Detected cases of plagiarism will lead to a significant penalty of your course grade at the end of the semester.

Rule 2: no late submissions! Even if it is late by one minute, it will be ignored. Learning to plan your schedule according to deadlines is part of your education and an invaluable professional asset.

What to submit: a) the source code of your project fully documented (with javadoc), b) a nicely formatted pdf report of your design decision explanations and class diagrams and c) an executable demo that fully illustrates your program’s capabilities whenever code is requested .

*******************************************************************************

Question 1: You have implemented the Singleton design pattern as a class named (very originally) “Singleton”.

  1. What happens if someone tries to clone a Singleton object using the clone() method inherited from Object? Does it lead to the creation of a second distinct Singleton object? Justify your answer. (5 points)

  2. Clonin Singletons should not be allowed. How can you prevent the cloning of a Singleton object? (5 points)

  3. Let’s assume the class Singleton is a subclass of class Parent, that fully implements the Cloneable interface. How would you answer questions 1 and 2 in this case? (10 points)

Question 2 (30 points): You are now employed by ZırhSan A.Ş. A private company specializing in the design and production of exoskeleton armored suits for military personnel, equipped with various custom weapons.

There are 3 basic types of suits: dec (500k TL, 25kg), ora (1500k TL, 30kg) and tor (5000k TL, 50kg).

Each of these suits can be equipped with the following accessories:

  • Flamethrower (50k TL per item, 2k)

  • AutoRifle (30k TL per item, 1.5kg)

  • RocketLauncher (150k TL per item, 7.5kg)

  • Laser (200k TL per item, 5.5kg)

  • A customer can demand any custom combination of accessories: such as a dec suit with 1 flamethrower, 2 automatic rifles and 1 rocket launcher.

Your task is to develop a piece of software in Java able to calculate the total cost and weight of an equipped suit (total price = basic suit price + prices of the accessories). The user of the software should be able to designate any combination of accessories dynamically at runtime. Your design should be flexible and easy to accommodate new accessories and suit types.

Question 3: You quit your job at ZırhSan, as the schedules were hectic (initially advertised as a “esnek çalışma saatlerine sahip pozisyon, bıdı bıdı”) and you are now employed by Turkish Aerospace Industries (TAI). TAI is about to launch the new series TPX series of passenger planes, consisting of 3 models.

Model

Purpose

Skeleton

Engine

Seating

TPX 100

Domestic flights

Aluminum alloy

Single jet engine

50 seats

TPX 200

Domestic and short international

Nickel alloy

Twin jet engines

100 seats

flights

TPX 300

Transatlantic flights

Titanium alloy

Quadro jet engines

250 seats

The production of a plane is conducted in the following order:

  1. constructSkeleton()

  1. placeEngines()

and 3) placeSeats()

Use the Factory Method design pattern to develop a Java program simulating the production of TPX planes. (20 points)

Business is booming. TAI is now exporting planes to the international market. And the models are customized according to local needs.

Market

Engine injection type

Seating cover

Domestic

Turbojet

Velvet

Eurasia

Turbofan

Linen

Other

Geared turbofan

Leather

Redesign and re-implement your Java program simulating the production of TPX planes for all 3 markets, using this time the Abstract Factory design pattern (30 points).