Java代写 | COIS2240 Assignment#3

本次Java代写是练习面向对象和JavaFX图形库

COIS2240 Assignment#3
Submission deadline: April 5, 2020 23:59:59.
Question#1 (Total 4 points)
import java.util.Date;
public class InternetCharge implements Cloneable {
double bandwith;
boolean isLimited;
double monthlyRate;
Date startDate;
public InternetCharge(double bandwith, boolean limited,
double monthlyRate, Date startDate) {
this.bandwith = bandwith;
this.isLimited = limited;
this.monthlyRate = monthlyRate;
this.startDate = startDate;
}
public void setMonthlyRate(int rate) throws Exception {
if (rate < 0)
throw new Exception(“Rate cannot be negative”);
if (isLimited) {
this.monthlyRate = rate * 1;
} else if (!isLimited) {
this.monthlyRate = rate * 1.5;
}
}
public double getMonthlyCharge() {
return monthlyRate * bandwith * 0.5;
}
@Override
public Object clone() {
// Write your code here
COIS2240 Assignment#3 Page 2 of 4
}
}
a.) The method clone is provided in the Object class. Override the method clone to perform deep
copy for InternetCharge. (2 points)
b) Write two test methods for InternetCharge. The first test method is to test whether the
getMonthlyCharge operation is correct. The second test method is to test whether an exception is
thrown by the setMonthlyRate method. (2 points)
Question#2: (Total 3 points)
a) What the Adapter pattern is useful for? What is the difference between class adapter and
object adapter? (1 points)
b) Explain what Singleton pattern is useful for? What is the difference between lazy and eager
instantiation in the Singleton design pattern. (1 points)
c) Explain what Observer pattern is useful for? (1 points)
Question#3: (Total 6 points)
a) Draw a class diagram that models the following: Animals can eat and move. Birds are animals
that can fly. Chicken, Eagle, Cow, Rabbit, and Tiger are animals. Chicken and Eagle are birds.
Chicken and Cow are edible. You can not create an object of Animal or Bird. Peas and Carrot are
Plants. Plants are edible. Tigers eat any Animal, Chicken eat Peas, Cows eat any plant, Rabbits
eat Carrot, and Eagle eat any Animal. Make sure to include methods that model behaviours in
each class. If something can be modelled using association, the preference should be given to
using association. (3 points)
b) Write a Java program that include classes and interfaces for the above scenario. Each concrete
class should override the toString() method to print the name of the animal or plant. Edible
animals should have a method that returns string called howToEat(). For edible animals,
howToEat() should return “roast it” and for plants, this method should return “eat as you wish”.
In addition, you have to write a main method in a separate class. In the main method, you have
create an object for each animal or plant, and call toString on it. For edibles, you have to print the
string returned from howToEat(). (3 points)
Question#4: (4 points)
A passenger wants to book a flight. First, she checks if the flight has an available seat, if yes, a
booking object is created and the passenger is added to the booking object. If the flight doesn’t
have available seats, it will create a waitlist object and will add the passenger to the object. Draw
a sequence diagram that illustrates this scenario.
COIS2240 Assignment#3 Page 3 of 4
Question#5: (4 points)
In a course registration system, the student enters the course ID and student ID for registration.
In parallel, the system verifies if the student has the prerequisites for the course and if the course
is not full. If both conditions are fulfilled, the system will register the student in the course and
will exit successfully. If one of the conditions is not fulfilled, the system will exit unsuccessfully.
Draw an activity diagram that illustrates this scenario.
Question#6: (3 points)
On Week#10, we discussed JavaFX. Explain in writing the relationship between a Stage, Scene,
Nodes, and Parents (Control or Pane). Illustrate using two examples, one using Shape and
another using a Control such as Label.
Question#7: (Total 4 points)
a) Write a Java program to create a file named Assignment3.txt if it does not exist. Write 100
integers created randomly into the file using text I/O. Integers are separated by spaces in the
file. Read the data back from the file and display the data in creasing order. (2 points)
b) Now, in the same Java program replace each number by its multiple of 2. For example, if the
number was 4, replace it with 8. (2 points)
Submit Java source file, screenshots of your output and the text file.
Question#8: (2 points)
What is the output of the following program:
class Test {
public static void main(String[] args) {
try {
method();
System.out.println(“After the method call”);
}
catch (RuntimeException ex) {
System.out.println(“RuntimeException”);
}
catch (Exception ex) {
System.out.println(“Exception”);
}
}
static void method() throws Exception {
COIS2240 Assignment#3 Page 4 of 4
try {
String s = “5.6”;
Integer.parseInt(s); // Cause a NumberFormatException
int i = 0;
int y = 2 / i;
System.out.println(“Welcome to Java”);
}
catch (NumberFormatException ex) {
System.out.println(“NumberFormatException”);
throw ex;
}
catch (RuntimeException ex) {
System.out.println(“RuntimeException”);
}
}
}


程序代写代做C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: [email protected]  微信:itcsdx


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

blank

发表评论