
![Short Answer Questions Q1. [10 marks] Implementa class called Circle that implements the MovableSizable interface, and adds a](http://img.homeworklib.com/images/45419bc1-dae7-4af2-a53d-e5d105c4d6af.png?x-oss-process=image/resize,w_560)
![Short Answer Questions Q2. [5 marks] Drawa UML class diagram of the MovableSizable interface and your Circle class, showing a](http://img.homeworklib.com/images/2e0ff23d-7a2e-413c-b9cb-ca0e3d6db68d.png?x-oss-process=image/resize,w_560)
![Short Answer Questions Q3. [5 marks] Write a JUnit 5.0 test class, that has two tests of your Circle class: 1) one test that](http://img.homeworklib.com/images/2b5f514d-45f3-4ea7-9861-fe3faf7e91cd.png?x-oss-process=image/resize,w_560)
![Short Answer Questions Q4. [10 marks] The following UML class diagram describes the structure of a Java program for managing](http://img.homeworklib.com/images/60799c2d-5b8e-45e3-b0e6-aa5ba3957a7d.png?x-oss-process=image/resize,w_560)
[Continued] Your Course class should have:
1)a getter for the course 'code', so that it is read-only;
2)a getter and setter for the lecturer attribute, so that it is readable and writable;
3)a constructor that creates the associations shown in the UML diagram;
4)an enrolStudent method that adds a given Student object into the 'enrolled' set;
5)a withdrawStudent method that removes a given Student object from the 'enrolled' set and returns true if the student was successfully found and removed, false otherwise.
Hi, I have answered this question before. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
// Circle.java
public class Circle implements MovableSizable {
//fields
private int x, y;
private double radius;
//constructor
public Circle(int x, int y, double radius) {
if (radius <= 0) {
//invalid radius, throwing IllegalArgumentException
throw new IllegalArgumentException();
}
//initializing values
this.x = x;
this.y = y;
this.radius = radius;
}
@Override
public void resize(double scale) {
//resizing radius by given scale
radius *= scale;
}
@Override
public int getHeight() {
//rounding height and returning it
return (int) Math.round(radius*2);
}
@Override
public int getWidth() {
//rounding width and returning it
return (int) Math.round(radius*2);
}
@Override
public void moveTo(int x, int y) {
//updating x and y
this.x = x;
this.y = y;
}
@Override
public int getX() {
return x;
}
@Override
public int getY() {
return y;
}
}
//UML diagram

// CircleTest.java
import static org.junit.Assert.*;
import org.junit.Test;
public class CircleTest {
@Test
public void test1() {
// creating a circle. testing getter methods
Circle circle = new Circle(0, 0, 3.6);
assertEquals(circle.getX(), 0);
assertEquals(circle.getY(), 0);
assertEquals(circle.getHeight(), 7);
assertEquals(circle.getWidth(), 7);
// testing moveTo and resize methods
circle.moveTo(10, 20);
circle.resize(3.0);
assertEquals(circle.getX(), 10);
assertEquals(circle.getY(), 20);
assertEquals(circle.getHeight(), 22);
assertEquals(circle.getWidth(), 22);
}
@Test
public void test2() {
// ensuring that IllegalArgumentException is thrown when a negative or
// zero radius is given as argument
try {
Circle circle = new Circle(0, 0, -2);
fail("No exception thrown. Was expecting IllegalArgumentException");
} catch (IllegalArgumentException e) {
} catch (Exception e) {
fail("Should throw IllegalArgumentException, got: " + e);
}
}
}
// Course.java
import java.util.ArrayList;
public class Course {
// attributes
private String code; // course code
private ArrayList<Student> enrolled; // list of students enrolled
private Staff lecturer; // lecturer
// (3)a constructor that creates the associations shown in the UML diagram
public Course(String code) {
this.code = code;
// initializing list
enrolled = new ArrayList<Student>();
}
// 1)a getter for the course 'code', so that it is read-only;
public String getCode() {
return code;
}
// 2)a getter for the lecturer attribute, so that it is readable
public Staff getLecturer() {
return lecturer;
}
// 2)a setter for the lecturer attribute, so that it is writable;
public void setLecturer(Staff lecturer) {
this.lecturer = lecturer;
}
// 4)an enrolStudent method that adds a given Student object into the
// 'enrolled' set;
public void enrolStudent(Student s) {
// simply adding
enrolled.add(s);
}
// 5)a withdrawStudent method that removes a given Student object from the
// 'enrolled' set and returns true if the student was successfully found and
// removed, false otherwise.
public boolean withdrawStudent(Student s) {
// finding the student
for (int i = 0; i < enrolled.size(); i++) {
if (enrolled.get(i).getId() == s.getId()) {
// found, removing and returning true
enrolled.remove(i);
return true;
}
}
return false; // not found
}
}
[Continued] Your Course class should have: 1)a getter for the course 'code', so that it is...
[Continued] Your Course class should have:
1)a getter for the course 'code', so that it is read-only;
2)a getter and setter for the lecturer attribute, so that it is
readable and writable;
3)a constructor that creates the associations shown in the UML
diagram;
4)an enrolStudent method that adds a given Student object into
the 'enrolled' set;
5)a withdrawStudent method that removes a given Student object
from the 'enrolled' set and returns true if the student was
successfully found and removed,...
Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use the same Circle UML as below and make extensions as marked and as needed. Given below is a UML for the Painting Class. You will need to write PaintingHeader.h and Painting.cpp. The Painting Class UML contains a very basic skeleton. You will need to flesh out this UML and add more instance variables and methods as needed. You do NOT need to write a...
java language
Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...
I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a void method named howToColor(). void howToColor(); } GeometricObject class: public class GeometricObject { } Sqaure class: public class Square extends GeometricObject implements Colorable{ //side variable of Square double side; //Implementing howToColor() @Override public void howToColor() { System.out.println("Color all four sides."); } //setter and getter methods for Square public void setSide(double side) { this.side = side; } public double getSide() { return...
JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you created in the previous lab. In this lab, create a Student class with the following class variable: Student name: Name (Note: Name is a datatype) Student Id: String Create the getter and setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Complete...
Java code for the following inheritance hierarchy figure..
1. Create class Point, with two private
instance variables x and y that represented for the coordinates for
a point.
Provide constructor for initialising two instance variables.
Provide set and get methods
for each instance variable,
Provide toString method to return formatted
string for a point coordinates.
2. Create class Circle, its inheritance from
Point.
Provide a integer private
radius instance variable.
Provide constructor to
initialise the center coordinates and radius for...
Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course { /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...
Write a Python class, Circle, constructed by a radius and two methods which will compute the area and the perimeter of a circle. Include the constructor and other required methods to set and get class attributes. Create instances of Circle and test all the associated methods. Write a Python class, Rectangle, constructed by length and width and a method which will compute the area of a rectangle. Include the constructor and other required methods to set and get class attributes....
Given a class called Student and a class called Course that
contains an ArrayList of Student. Write a method called
getDeansList() as described below. Refer to Student.java below to
learn what methods are available.
I will paste both of the simple .JAVA codes below
COURSE.JAVA
import java.util.*;
import java.io.*;
/******************************************************
* A list of students in a course
*****************************************************/
public class Course{
/** collection of Students */
private ArrayList<Student> roster;
/*****************************************************
Constructor for objects of class Course
*****************************************************/...
Receiveing this error message when running the Experts code below please fix ----jGRASP exec: javac -g GeometricObject.java GeometricObject.java:92: error: class, interface, or enum expected import java.util.Comparator; ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. 20.21 Please code using Java IDE. Please DO NOT use Toolkit. You can use a class for GeometricObject. MY IDE does not have access to import ToolKit.Circle;import. ToolKit.GeometricObject;.import ToolKit.Rectangle. Can you code this without using the ToolKit? Please show an...