You will create a single file using Violet for Part 1 and 2 below. Submit the fi
ID: 3711036 • Letter: Y
Question
You will create a single file using Violet for Part 1 and 2 below. Submit the file to your instructor for grading using Blackboard. Part 1 (8 pts) Using Violet create a class diagram for a Shape class. Shapes have a name, an X coordinate, and a Y coordinate. The two coordinates give the position of the shape. Make sure that you show the visibility of all fields and methods of the class. Part 2 (24 pts) Extend the above class diagram for shape by adding three derived classes; Circle, Triangle, and Rectangle. The classes will have the following additional fields: • Circle 1. radius • Triangle 1. base 2. height • Rectangle 1. width 2. height Make sure that you show the visibility of all fields and methods of the class.
Explanation / Answer
package Shapes;
public class Rectangular extends Shape{
public double width;
public double length;
private String name;
private String X_cord;
private String Y_cord;
public Rectangular(String name, String x_cord, String y_cord, double width,
double length) {
super(name, x_cord, y_cord);
this.width = width;
this.length = length;
}
/**
* @return the width
*/
public double getwidth() {
return width;
}
/**
* @param width the width to set
*/
public void setwidth(double width) {
this.width = width;
}
/**
* @return the length
*/
public double getlength() {
return length;
}
/**
* @param length the length to set
*/
public void setlength(double length) {
this.length = length;
}
@Override
public double Area() {
// TODO Auto-generated method stub
return this.width *this.length;
}
}
2)
package Shapes;
public class Traingle extends Shape{
public double base ;
public double height ;
private String name;
private String X_cord;
private String Y_cord;
@Override
public double Area() {
// TODO Auto-generated method stub
return 1/2*(this.base*this.height);
}
public Traingle(String name, String x_cord, String y_cord, double base,
double height) {
super(name, x_cord, y_cord);
this.base = base;
this.height = height;
}
/**
* @return the side
*/
public double getbase() {
return this.base;
}
/**
* @param side the side to set
*/
public void setbase(double base) {
this.base = base;
}
/**
* @return the side
*/
public double getheight() {
return this.height;
}
/**
* @param side the side to set
*/
public void setheight(double height) {
this.height = height;
}
}
3)
package Shapes;
public class Shape {
public Shape(String name, String x_cord, String y_cord) {
super();
this.name = name;
X_cord = x_cord;
Y_cord = y_cord;
}
private String name;
private String X_cord;
private String Y_cord;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the x_cord
*/
public String getX_cord() {
return X_cord;
}
/**
* @param x_cord the x_cord to set
*/
public void setX_cord(String x_cord) {
X_cord = x_cord;
}
public double Area(){
return 0.0;
}
}
4)
package Shapes;
import java.util.Arrays;
public class Circle extends Shape{
public double radius;
private String name;
private String X_cord;
private String Y_cord;
public Circle(double radius, String name, String x_cord, String y_cord) {
super(name, x_cord, y_cord);
this.radius = radius;
}
/**
* @return the radius
*/
public double getRadius() {
return radius;
}
/**
* @param radius the radius to set
*/
public void setRadius(double radius) {
this.radius = radius;
}
@Override
public double Area() {
// TODO Auto-generated method stub
return 3.14*this.radius*this.radius;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.