application of programming in java

Task 1

For this task you will create a Subject class, whose instances will represent the subjects for study at a university. A subject will have a name, just a String, and a subject code, which is a six-character String. The first three characters of a subject code are alphabetic and the last three are numeric. The first three characters define the subject’s discipline area. A subject code must be unique but do not need to check subject name for uniqueness.

You will also write a TestSubject class to test the use of your Subject class. In particular this will maintain an array of subjects. In order to manage the uniqueness of the subject codes, your program will need to display information about existing subject codes as well as checking that any new subject code supplied by the user is not the same as any existing subject code.

The following state and functionality should be provided for the Subject class:

  • Two fields will hold the subject’s name (Programming in java 1) and the six-character subject code (ITC206).
  • A constructor will allow a name and a new, validated subject code to be provided when a new subject is created.
  • Getters will provide access to the attributes.
  • An accessor method called codeMatches will return a boolean value indicating if the subject’s code matches the string argument provided. “Matches” is used here in the same sense as for the matches method of the String class.
  • A toString method will return a string containing the subject code and subject name.

To assist with managing subject codes and their uniqueness you will provide the Subject class with some class methods as follows (you may add more method9s) if you need):

  • An isValidCode method will accept a string that is a possible new subject code, and return a boolean indicating whether it satisfies the structural requirements for a subject code (i.e. first three characters are letters and last three characters are digits).
  • A codeExists method will accept an array of Subject objects and a possible new subject code. It will return a boolean indicating whether that code has already been allocated to one of the subjects in the array.

Your TestSubject program will perform the following sequence of actions, using good design techniques such as in the appropriate use of methods:

  • An initial array of Subject objects will be created from any data in a file that was previously saved by the program (not using programming in java, just open a text file and write subject name and code and then save the file). You need to read those data from the file and process other requirements (using java programming)
  • The user interaction will then proceed to allow the user to add one or more new subjects to the array. If the user wishes to add new subjects, the existing subjects should be displayed. Each subject code entered by the user should be checked against the existing subject codes. The user can enter any new subject, but only non-existing subject codes and their names should be added in the subject list, otherwise, give opportunity to enter new code if the entered subject code already exists in the list. The user should be given the choice of repeating the processing for more subjects.
  • When the user has finished adding subjects, and only if subjects have indeed been added, the program will overwrite the data file with the updated data if anyone open the file using file explorer, he/she can see the all subjects including the newly added subjects.


  • You may use an ArrayList to implement an array if you prefer and it is appropriate.

You need to submit java and class files and sample output (for detail please see marking guide and presentation below).

Task 2

Design a class named MyRectangle2D class that extends GeometricObject class

(see GeometricObject class in the textbook or below).

The MyRectangle2D class contains:

  • Two double data fields named x and y that specify the centre of the rectangle with get and set methods. (Assume that the rectangle sides are parallel to x- or y- axis.)
  • Write get and set methods to access the double data fields width and height
  • Write a no-argument constructor that creates a default rectangle (or square) with (0, 0) for (x, y) and 1 for both width and height.
  • Write A constructor that creates a rectangle with the specified x, y, width, and height,use the following method header:

public MyRectangle2D(double x, double y, double width, double height)

  • Write a method named getArea(), that returns the area of the rectangle.
  • Write a method named getPerimeter() that returns the perimeter of the rectangle.
  • Write a method named contains, has two double type of parameters:

contains (double x, double y)

It returns true if the specified point (x, y) is inside this rectangle.

  • Overload method contains with one parameter MyRectangle2D:

contains (MyRectangle2D r)

This method returns true if the specified rectangle is inside this rectangle.

  • Draw the UML diagram for the class. To save time, omit the accessor and mutator methods.
  • Implement data fields, all constructors, methods getArea(), getPerimeter(), and contains(double x, double y).
  • Write a test program to create objects and test properties: getArea(), getPerimeter(), contains(double x, double y) and contains(MyRectangle2D r).

Draw the UML diagram that involves the class Triangle. Implement the clas. Write a test program that creates a Triangle object with sides 3.0, 4.0, 5.0, color yellow and filled true, and displays the area, perimeter, color, and whether filled or not. GeometricObject class is given below.


You need to submit java and class files, UML diagram, and sample output .

“Get 15% discount on your first 3 orders with us”
Use the following coupon

Order Now