Answered step by step
Verified Expert Solution
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 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 InternetChargedouble bandwith, boolean limited double monthlyRate, Date startDate
this.bandwith bandwith;
this.isLimited limited;
this.monthlyRate monthlyRate;
this.startDate startDate;
public void setMonthlyRateint rate throws Exception
if rate
throw new ExceptionRate cannot be negative";
if isLimited
this.monthlyRate rate ;
else if isLimited
this.monthlyRate rate ;
public double getMonthlyCharge
return monthlyRate bandwith ;
@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 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 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 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
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
package junitTest;
public class Book
private String title;
private String author;
private int pages;
private int publishedYear;
public BookString 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started