import javax.swing.JOptionPane; public class InheritanceTest { public static voi
ID: 3540368 • Letter: I
Question
import javax.swing.JOptionPane;
public class InheritanceTest {
public static void main(String[] args) {
Point[] shapeAR = new Point[3];
try {
shapeAR[0] = new Point(0, 0);
shapeAR[1] = new Square(0, 0);
shapeAR[2] = new Cube(0, 0);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Please Try AGAIN!!",
"ERROR!!", JOptionPane.ERROR_MESSAGE);
}
}
}
class Point {
protected double x;
protected double y;
private String xString, yString;// converted later to double x/y
public Point(double x1, double y1) {
x = x1;
y = y1;
}
public String getXString() {
return xString;
}
public String getYString() {
return yString;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public void getUserInput() {
xString = JOptionPane.showInputDialog("Enter for x:");
x = Double.parseDouble(xString);
yString = JOptionPane.showInputDialog("Enter for y:");
y = Double.parseDouble(yString);
}
public String toString1() {
return "X :" + x + " " + "Y :" + y + " ";
}
}
class Square extends Point {
protected double sideLength;
private String sideString;// Converted to Double
public double perimeter, area;
public Square(double x1, double y1) {
super(x1, y1);
}
public double getSideLength() {
return sideLength;
}
public String getSideStrength() {
return sideString;
}
public void getSideInput() {
super.getUserInput();
sideString = JOptionPane.showInputDialog("Enter for side length:");
sideLength = Double.parseDouble(sideString);
perimeter = sideLength * 4;
area = sideLength * sideLength;
}
public String toString1() {
return "X :" + x + " " + "Y :" + y + " " + "Side Length :"
+ sideLength + "Perimeter :" + perimeter + " " + "Area :"
+ area + " ";
}
}
class Cube extends Square {
public Cube(double x1, double y1) {
super(x1, y1);
}
protected double depth, volume;
public void getVoidInput() {
super.getUserInput();
super.getSideInput();
depth = 6 * area;
volume = depth * area;
}
public String toString() {
return "X :" + x + " " + "Y :" + y + " " + "Depth:" + depth + " "
+ "Area :" + area + " " + "Volume :" + volume + " ";
}
}
%u3000
Explanation / Answer
import javax.swing.JOptionPane;
public class InheritanceTest {
public static void main(String[] args) {
Point[] shapeAR = new Point[3];
try {
shapeAR[0] = new Point(0, 0);
shapeAR[1] = new Square(0, 0);
shapeAR[2] = new Cube(0, 0);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Please Try AGAIN!!",
"ERROR!!", JOptionPane.ERROR_MESSAGE);
}
}
}
class Point {
protected double x;
protected double y;
private String xString, yString;// converted later to double x/y
public Point(double x1, double y1) {
x = x1;
y = y1;
}
public String getXString() {
return xString;
}
public String getYString() {
return yString;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public void getUserInput() {
xString = JOptionPane.showInputDialog("Enter for x:");
x = Double.parseDouble(xString);
yString = JOptionPane.showInputDialog("Enter for y:");
y = Double.parseDouble(yString);
}
public String toString1() {
return "X :" + x + " " + "Y :" + y + " ";
}
}
class Square extends Point {
protected double sideLength;
private String sideString;// Converted to Double
public double perimeter, area;
public Square(double x1, double y1) {
super(x1, y1);
}
public double getSideLength() {
return sideLength;
}
public String getSideStrength() {
return sideString;
}
public void getSideInput() {
super.getUserInput();
sideString = JOptionPane.showInputDialog("Enter for side length:");
sideLength = Double.parseDouble(sideString);
perimeter = sideLength * 4;
area = sideLength * sideLength;
}
public String toString1() {
return "X :" + x + " " + "Y :" + y + " " + "Side Length :"
+ sideLength + "Perimeter :" + perimeter + " " + "Area :"
+ area + " ";
}
}
class Cube extends Square {
public Cube(double x1, double y1) {
super(x1, y1);
}
protected double depth, volume;
public void getVoidInput() {
super.getUserInput();
super.getSideInput();
depth = 6 * area;
volume = depth * area;
}
public String toString() {
return "X :" + x + " " + "Y :" + y + " " + "Depth:" + depth + " "
+ "Area :" + area + " " + "Volume :" + volume + " ";
}
}
import javax.swing.JOptionPane;
public class InheritanceTest {
public static void main(String[] args) {
Point[] shapeAR = new Point[3];
try {
shapeAR[0] = new Point(0, 0);
shapeAR[1] = new Square(0, 0);
shapeAR[2] = new Cube(0, 0);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Please Try AGAIN!!",
"ERROR!!", JOptionPane.ERROR_MESSAGE);
}
}
}
class Point {
protected double x;
protected double y;
private String xString, yString;// converted later to double x/y
public Point(double x1, double y1) {
x = x1;
y = y1;
}
public String getXString() {
return xString;
}
public String getYString() {
return yString;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public void getUserInput() {
xString = JOptionPane.showInputDialog("Enter for x:");
x = Double.parseDouble(xString);
yString = JOptionPane.showInputDialog("Enter for y:");
y = Double.parseDouble(yString);
}
public String toString1() {
return "X :" + x + " " + "Y :" + y + " ";
}
}
class Square extends Point {
protected double sideLength;
private String sideString;// Converted to Double
public double perimeter, area;
public Square(double x1, double y1) {
super(x1, y1);
}
public double getSideLength() {
return sideLength;
}
public String getSideStrength() {
return sideString;
}
public void getSideInput() {
super.getUserInput();
sideString = JOptionPane.showInputDialog("Enter for side length:");
sideLength = Double.parseDouble(sideString);
perimeter = sideLength * 4;
area = sideLength * sideLength;
}
public String toString1() {
return "X :" + x + " " + "Y :" + y + " " + "Side Length :"
+ sideLength + "Perimeter :" + perimeter + " " + "Area :"
+ area + " ";
}
}
class Cube extends Square {
public Cube(double x1, double y1) {
super(x1, y1);
}
protected double depth, volume;
public void getVoidInput() {
super.getUserInput();
super.getSideInput();
depth = 6 * area;
volume = depth * area;
}
public String toString() {
return "X :" + x + " " + "Y :" + y + " " + "Depth:" + depth + " "
+ "Area :" + area + " " + "Volume :" + volume + " ";
}
}
import javax.swing.JOptionPane;
public class InheritanceTest {
public static void main(String[] args) {
Point[] shapeAR = new Point[3];
try {
shapeAR[0] = new Point(0, 0);
shapeAR[1] = new Square(0, 0);
shapeAR[2] = new Cube(0, 0);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Please Try AGAIN!!",
"ERROR!!", JOptionPane.ERROR_MESSAGE);
}
}
}
class Point {
protected double x;
protected double y;
private String xString, yString;// converted later to double x/y
public Point(double x1, double y1) {
x = x1;
y = y1;
}
public String getXString() {
return xString;
}
public String getYString() {
return yString;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public void getUserInput() {
xString = JOptionPane.showInputDialog("Enter for x:");
x = Double.parseDouble(xString);
yString = JOptionPane.showInputDialog("Enter for y:");
y = Double.parseDouble(yString);
}
public String toString1() {
return "X :" + x + " " + "Y :" + y + " ";
}
}
class Square extends Point {
protected double sideLength;
private String sideString;// Converted to Double
public double perimeter, area;
public Square(double x1, double y1) {
super(x1, y1);
}
public double getSideLength() {
return sideLength;
}
public String getSideStrength() {
return sideString;
}
public void getSideInput() {
super.getUserInput();
sideString = JOptionPane.showInputDialog("Enter for side length:");
sideLength = Double.parseDouble(sideString);
perimeter = sideLength * 4;
area = sideLength * sideLength;
}
public String toString1() {
return "X :" + x + " " + "Y :" + y + " " + "Side Length :"
+ sideLength + "Perimeter :" + perimeter + " " + "Area :"
+ area + " ";
}
}
class Cube extends Square {
public Cube(double x1, double y1) {
super(x1, y1);
}
protected double depth, volume;
public void getVoidInput() {
super.getUserInput();
super.getSideInput();
depth = 6 * area;
volume = depth * area;
}
public String toString() {
return "X :" + x + " " + "Y :" + y + " " + "Depth:" + depth + " "
+ "Area :" + area + " " + "Volume :" + volume + " ";
}
}
import javax.swing.JOptionPane;
public class InheritanceTest {
public static void main(String[] args) {
Point[] shapeAR = new Point[3];
try {
shapeAR[0] = new Point(0, 0);
shapeAR[1] = new Square(0, 0);
shapeAR[2] = new Cube(0, 0);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Please Try AGAIN!!",
"ERROR!!", JOptionPane.ERROR_MESSAGE);
}
}
}
class Point {
protected double x;
protected double y;
private String xString, yString;// converted later to double x/y
public Point(double x1, double y1) {
x = x1;
y = y1;
}
public String getXString() {
return xString;
}
public String getYString() {
return yString;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public void getUserInput() {
xString = JOptionPane.showInputDialog("Enter for x:");
x = Double.parseDouble(xString);
yString = JOptionPane.showInputDialog("Enter for y:");
y = Double.parseDouble(yString);
}
public String toString1() {
return "X :" + x + " " + "Y :" + y + " ";
}
}
class Square extends Point {
protected double sideLength;
private String sideString;// Converted to Double
public double perimeter, area;
public Square(double x1, double y1) {
super(x1, y1);
}
public double getSideLength() {
return sideLength;
}
public String getSideStrength() {
return sideString;
}
public void getSideInput() {
super.getUserInput();
sideString = JOptionPane.showInputDialog("Enter for side length:");
sideLength = Double.parseDouble(sideString);
perimeter = sideLength * 4;
area = sideLength * sideLength;
}
public String toString1() {
return "X :" + x + " " + "Y :" + y + " " + "Side Length :"
+ sideLength + "Perimeter :" + perimeter + " " + "Area :"
+ area + " ";
}
}
class Cube extends Square {
public Cube(double x1, double y1) {
super(x1, y1);
}
protected double depth, volume;
public void getVoidInput() {
super.getUserInput();
super.getSideInput();
depth = 6 * area;
volume = depth * area;
}
public String toString() {
return "X :" + x + " " + "Y :" + y + " " + "Depth:" + depth + " "
+ "Area :" + area + " " + "Volume :" + volume + " ";
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.