Problem: Write a Java program that parses a text file with commands for different types of shapes containing information about their size, coordinates, and position. The program should calculate the area of each shape.
Decompose the problem following Model-View-Controller practices.
File format: shape,dimension info, x, y, color
triangle,side:10,100,150,BLUE
square,side:15,20,15,YELLOW
circle,radius:12,50,60,GREEN
Draw a UML diagram based on your group discussion on how to decompose this problem
Your diagram should have a superclass, and subclasses for model
. It should also have a controller
class and a view
class
You have 15 minutes.
model
Equilateral triangle area = (side² × √3)/ 4
JUnit tests:
@Test
void testTriangleArea() {
Shape triangle = new Triangle(4);
Assertions.assertEquals(triangle.getArea(), 6.93);
}
@Test
void testSquareArea() {
Shape square = new Square(4);
Assertions.assertEquals(square.getArea(), 16);
}
@Test
void testCircleArea() {
Shape circle = new Circle(4);
Assertions.assertEquals(circle.getArea(), 50.27);
}
view
(ascii version)import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class View {
public static void main(String[] args) throws FileNotFoundException {
Controller controller = new Controller();
File file = new File(args[0]);
Scanner reader = new Scanner(file);
while (reader.hasNext()) {
controller.parseLine(reader.nextLine());
}
System.out.println(controller);
reader.close();
}
}
view
(JavaFX version)What GUI components do we need?
What GUI-specific methods should be created?