[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 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...
Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...