cois 2240h software design and modelling assignment 3 class diagram se
Search for question
Question
COIS 2240H - Software Design & Modelling
Assignment 3 - Class Diagram, Sequence Diagrams, Java Code and Unit Testing Total points: 100
Note. The assignment should be attempted through individual efforts, and any concerns related to academic integrity will be handled in accordance with the university's guidelines.
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;
Fall 2023
COIS 2240H - Software Design & Modelling
Assignment 3 - Class Diagram, Sequence Diagrams, Java Code and Unit Testing Total points: 100
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
}
}
Fall 2023
COIS 2240H - Software Design & Modelling
Assignment 3 - Class Diagram, Sequence Diagrams, Java Code and Unit Testing Total points: 100
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().
Fall 2023
COIS 2240H - Software Design & Modelling
Assignment 3 - Class Diagram, Sequence Diagrams, Java Code and Unit Testing
Total points: 100
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 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.
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.
Fall 2023
COIS 2240H - Software Design & Modelling
Assignment 3 - Class Diagram, Sequence Diagrams, Java Code and Unit Testing Total points: 100
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; }
Fall 2023
COIS 2240H - Software Design & Modelling Assignment 3 - Class Diagram, Sequence Diagrams, Java Code and Unit Testing Total points: 100
public int getPages() { return pages; }
public int getPublishedYear() { return publishedYear; }
public boolean isClassic() { return publishedYear < 2000; }
}
The Junit test code:
package junitTest;
import static org.junit.jupiter.api.Assertions .*;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue;
public class BookTest {
@Test
Fall 2023
COIS 2240H - Software Design & Modelling
Assignment 3 - Class Diagram, Sequence Diagrams, Java Code and Unit Testing Total points: 100
public void testTitleAndAuthor() {
// Write code here to create a test case to ensure that the title and author //attributes of a 'Book' object are correctly set and retrieved.
//Example of parameters that can be used: ("Java Programming", "John //Doe", 300, 2010)
} @Test
public void testPages() {
// Write code here to create a test case to ensure that that the pages //attribute of a 'Book' object is correctly set and retrieved.
//Example of parameters that can be used: ("Data Structures", //"Jane //Smith", 500, 1998)
}
@Test
public void testPublishedYear() {
// Write code here to create a test case to check if the publishedYear //attribute of a 'Book' object is correctly set and retrieved.
//Examples of parameters that can be used: ("Algorithms", "Alan Turing", //400, 1940);
}
@Test public void testIsClassic() {
// Write code here to create a test case to confirm that the isClassic method //of the Book class correctly identifies classic books published before the //year 2000.
//Examples of parameters that can be sued: ("Classic Novel", "Classic //Author", 200, 1950)
Fall 2023
COIS 2240H - Software Design & Modelling
Assignment 3 - Class Diagram, Sequence Diagrams, Java Code and Unit Testing Total points: 100
@Test }
public void testEdgeCase() {
// Write code here to create a test case to handle an edge case, such as a //book with zero pages or a book published in the year 2000.
//Example of parameters that can be used: ("Edge Case", "Edge Author", 0, //2000)
}
}
Fall 2023
COIS 2240H - Software Design & Modelling
Assignment 3 - Class Diagram, Sequence Diagrams, Java Code and Unit Testing Total points: 100
Deliverables: (Zipped submissions will NOT be graded).
Question 1.
· The Java program source code (You must submit the program regardless whether it complete, correct of incorrect).
· Screenshot of the output
Question 2.
· Screenshot of the Class Diagram
· The java programing source code for the Class Diagram
· Screenshot of the output of the Java Code
Question 3.
· Screenshot of the Sequence Diagram
Question 4.
· The completed Java source Code
. Screenshot of the Unit Testing output. The output should show the test cases using Junit passed the test. See screenshot below:
Runs: 5/5 @ Errors 0 Il Failures 0
v h- BookTest (Runner: JUnit 5] (0.022 s) testedgeCase0 (0.12 s)
del testTicieAndAuthorO) (0,001 ) nil testPublishedYear0 (0.001 s) testisClassic() (0.001 s)
Fall 2023/nCOIS 2240H - Software Design & Modelling
Assignment 2- Sate, Activity Diagrams & Java programming Total points: 100
Note. The assignment should be attempted through individual efforts, and any concerns related to academic integrity will be handled in accordance with the university's guidelines.
Objectives:
· Understand the major concepts of Object Oriented Systems, and modelling the State Diagrams, Activity Diagrams and implementation in Java programming language
Question 1 (36 points)
Java Programing:
In the code provided below, you will find the class GeometricObject and Triangle. 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 (1-5).
public abstract class GeometricObject {
private String color = "white"; private boolean filled; private java.util.Date dateCreated; /* Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); }
/* Construct a geometric object with color and filled value */
protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled;
Fall 2023
COIS 2240H - Software Design & Modelling
Assignment 2- Sate, Activity Diagrams & Java programming Total points: 100
/ ** Return color */ } public String getColor() {
return color; }
/ ** Set a new color */
public void setColor(String color) { this.color = color; }
/ ** Return filled. Since filled is boolean,
* the get method is named isFilled */ public boolean isFilled() { return filled; } / ** Set a new filled */
public void setFilled(boolean filled) { this.filled = filled; }
/ ** Get dateCreated */
public java.util.Date getDateCreated() { return dateCreated; } @Override
public String toString() { return "created on " + dateCreated + "\ncolor: " + color + " and filled: " + filled; }
/ ** Abstract method getArea */ public abstract double getArea();
/ ** Abstract method getPerimeter */
Fall 2023
COIS 2240H - Software Design & Modelling
Assignment 2- Sate, Activity Diagrams & Java programming Total points: 100
public abstract double getPerimeter(); }
class Triangle extends GeometricObject { private double side1 = 1.0, side2 = 1.0, side3 = 1.0;
/ ** Constructor */ public Triangle() { }
/ ** Constructor */ public Triangle(double side1, double side2, double side3) { this.side1 = side1; this.side2 = side2; this.side3 = side3; }
/* Override method findArea in GeometricObject */ public double getArea() { double s = (side1 + side2 + side3) / 2; return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3)); }
/ ** Override method findPerimeter in GeometricObject */ public double getPerimeter() { return side1 + side2 + side3; }
/ ** Override the toString method */
public String toString() { // Implement it to return the three sides return "Triangle: side1 = " + side1 + " side2 =" + side2 + " side3 = " + side3; }
}
Fall 2023
COIS 2240H - Software Design & Modelling
Assignment 2- Sate, Activity Diagrams & Java programming Total points: 100
class Test {
public static void main(String[] args) {
GeometricObject gObjectArray [] = new GeometricObject [4]; //Complete your code here
} private static void printAreaAndPerimeter(GeometricObject gObject) {
//Complete your code here
} }
1. Implement the classes Circle, EquilateralTriangle, Rectangle, and Square.
2. Implement the method printAreaAndPerimeter in the Test class that prints the area and the perimeter of the passed GeometricObject.
3. In the Test class, create an array of GeometricObject of size 5. The first element should be assigned to a Circle object: new Circle(4,4,4). The second element should be assigned to an EquilateralTriangle object: new EquilateralTriangle(3). The third element should be assigned to a Triangle object: new Triangle(3,3,3). The fourth element should be assigned to a Rectangle object: new Rectangle(2,2). The fifth element should be assigned to a Square object: new Square(10).
4. Pass each element in the array to printAreaAndPerimeter.
Fall 2023
COIS 2240H - Software Design & Modelling
Assignment 2- Sate, Activity Diagrams & Java programming Total points: 100
5. Compile, Run, and take a screenshot of the output and submit to Blackboard (you must submit the program regardless whether it complete or incomplete, correct or incorrect)
Questions 2 (32 points)
Modelling: State Diagram
Draw a state diagram that models a BankAccount object: a bank account can either have enough cash or be out of cash. If the account is out of cash, it will allow for money to deposited. If the account has enough cash, it will allow for money to be deposited and withdrawn. The account is out of cash if the amount in the account is below a predetermined minimum.
Questions 3 (32 points)
Modelling: Activity Diagram
In an online purchasing system, the buyer requests to buy an item. In parallel, the system looks up whether the item exists in the store and verifies if the buyer has an account with the system. If the buyer does not have an account, the system will ask for registration info from the buyer to open an account. If the buyer does not provide registration info, the system exits. If the item does not exist in the store, the system exits. If the item exists, the system will check if the item price is less than or equal to buyer's account balance. If the buyer has enough money in the account to purchase the item, the system completes the purchase order successfully. If the buyer does not have enough money, the system exits.
Fall 2023
COIS 2240H - Software Design & Modelling
Assignment 2- Sate, Activity Diagrams & Java programming Total points: 100
Deliverables:
1. "pdf" file containing Screenshots of the output for your Java program (Q1).
2. The Java program source code (Q1) (You must submit the program regardless whether it complete, correct of incorrect).
3. Screenshots of the State Diagrams and Activity Diagrams ( Q2 & Q3).
Note: Do not Zip your submissions. Zipped submissions will NOT be graded. Note. 10% will be deducted for every business day for late submission.
Fall 2023