Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Problem 1 (20 points) Assume the following requirements: Packets are sent from one location to another. Packets have a certain weight. Locations are characterized by their transportation facilities,...

1 answer below »



Problem 1 (20 points)

Assume the following requirements:

Packets are sent from one location to another. Packets have a certain weight. Locations are characterized by their transportation facilities, e.g. railway stations, airports and highway connections. Some locations are neighbored, i.e. there exists a direct transportation route between these locations. The transportation route between the locations has a certain length, i.e. the distance between the locations. Planes, trains, and trucks are used for transportation; each plane / train / truck may load a maximum packet weight. For each packet we want to know where it is, i.e. at which location or transport (plane, train, truck).

(i) Draw a class diagram for this problem; identify the semantic relationships and cardinalities. (10 points)

(ii) Draw the sequence diagram corresponding to a packet being sent from one location to another. (10 points)


Problem 2 (10 points)

Given the following UML write the corresponding (skeleton) Java code.


Problem 3 (20 points)

Integeris part of the Java API. Suppose you attempt to extend the Integer class and add a new method that returns the integer as a String that is written in hexadecimal.

(i) Explain why you're having trouble doing it. (5 points)

(ii) Alright, so the people who wrote the code had their reasons to not want you to extend the class. Give an example of how things could go very wrong if they didn't do it this way. (5 points)

(iii) Recommend a solution to the problem that doesn't involve subclassing. (10 points)


Problem 4 (10 points)

Randomis part of the Java API. It has various methods to generate random integers, random doubles, etc. However, Random does not have a method that will generate a random integer between two specified integers (like 3 and 11). That would be very useful in many applications. Your task is to create a class calledImprovedRandomthat can do everything that Random can do, but also adds this handy method. Use inheritance to extend Random.

Note: Your class is supposed to do everything that Random can do, so pay careful attention to what constructors should be possible. For example if Random can be instantiated with a seed parameter, then yours should be able to do the same.


Problem 5 (10 points)

StringTokenizeris part of the Java API. This class takes a string filled with words and, each time the method nextToken() is called, it returns the next word in the string. Create a new class namedImprovedStringTokenizerthat acts just like a StringTokenizer but has a new method that returns all of the words in a single array.

For example, if the string is "This class is easy", then your new method will return an array where the 0th element is "This", the 1st element is "class", the 2nd element is "is", and the 3rd element is "easy".


Answered 4 days After Feb 16, 2022

Solution

Arun Shankar answered on Feb 21 2022
117 Votes
Q1 (a)
(b)
Q2
------------------------------------------
class A
{
    public void method1(B var) { ... }
}
class C extends A
{
    public void method1(D var) { ... }
}
class E extends C
{
}
class D
{
    B var;
    F a, b;
}
class F
{
    D a, b, c, d, e;
}
Q3
------------------------------------------
(a) The Integer class is final in Java, so it cannot be extended.
(b) Allowing subclasses will affect the immutability of the Integer class. If a subclass was...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here