Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 ( 3 6 points ) Java Programing: In the code provided below, you will find the class GeometricObject and Triangle. Study the code

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;
}
/** 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 +"
color: "+ color +
" and filled: "+ filled;
}
/** Abstract method getArea */
public abstract double getArea();
/** Abstract method getPerimeter */
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;
}
}
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.
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 buyers 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.
Deliverables:
1.pdf file containing Screenshots of the

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

More Books

Students also viewed these Databases questions