Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: Understand the major concepts of Object Oriented Systems, modelling the Class Diagrams, Sequence Diagrams, implementation in Java and Unit Testing using Junit in Java.

Objectives:
Understand the major concepts of Object Oriented Systems, modelling the Class Diagrams, Sequence Diagrams, implementation in Java and Unit Testing using Junit in Java.
Question 1(30 points)
Java Programing:
Study the code well and then implement the required classes below. You can complete your implementation within this code as directed. The requirements are shown below the code (a & b).
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
}
}
a) The method clone is provided in the Object class. Override the method clone to perform deep copy for InternetCharge.
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.
Questions 2(30 points)
Modelling & coding: Class Diagram
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.
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().
Questions 3(10 points)
Modelling: Sequence Diagram
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 doesnt 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.
Question 4(30 points)
Software Unit testing using Junit
Utilize the provided "Book" class, to generate test cases for conducting unit testing using JUnit. The Book class is provided below and some of the JUnit code has been supplied under the Book Class code along with clarification for the missing code necessary for executing the test cases. The following test cases are needed:
Test Case - Title and Author:
Write a test case to ensure that the title and author attributes of a Book object are correctly set and retrieved.
Test Case - Pages:
Write a test case to verify that the pages attribute of a Book object is correctly set and retrieved.
Test Case - Published Year:
Implement a test case to check if the publishedYear attribute of a Book object is correctly set and retrieved.
Test Case - isClassic Method:
Write a test case to confirm that the isClassic method of the Book class correctly identifies classic books published before the year 2000.
Edge Case Test:
Create a test case to handle an edge case, such as a book with zero pages or a book published in the year 2000.
package junitTest;
public class Book {
private String title;
private String author;
private int pages;
private int publishedYear;
public Book(String title, String author, int pages, int publishedYear){
this.title = title;
this.author = author;
this.pages = pages;
this.publishedYear = publishedYear;
}
public String getTitle(){
return title;
}
public String getAuthor(){
return author;
}
public int getPages(){
return pages;
}
public int getPublishedYear(){
return publishedYe

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

Students also viewed these Databases questions

Question

Describe the importance of global talent management.

Answered: 1 week ago

Question

Summarize the environment of recruitment.

Answered: 1 week ago