QuestionQuestion

Material to submit for Task 1
1. You need to submit the java and class files
2. You also need to submit a doc/pdf file with following information:
a. Analysis: Describe the problem including input and output in your own words (not more than 400 words)
b. Testing: Describe how you test this program (not more than 400 words)
c. Output: Copy and paste a snapshot of the program output

Material to submit for Task 2
1. You need to submit the java and class files
2. You also need to submit a doc/pdf file with following information:
a. Analysis: Describe the problem including input and output in your own words (not more than 400 words)
b. Testing: Describe how you test this program (not more than 400 words)
c. Output: Copy and paste a snapshot of the program output

• 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.
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 and the six-character subject code.
• 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 getDiscipline will return a string containing the first three characters of the subject code.
• Another 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 (second class) with managing subject codes and their uniqueness you will provide the Subject class with some class methods as follows:
• An allDisciplines method will accept an array of Subject objects. It will return an array containing the different 3-character discipline codes represented in the array of subjects in alphabetically order.
• A codesPerDiscipline method will accept an array of Subject objects and a 3-character discipline code. It will return an array containing the different subject codes represented in the array of subjects for the particular discipline.
• 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.
• 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.
• A sortDisciplines method will accept an array of Subjects objects. It will return the sorted array of subjects in alphabetically order.

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.
• 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 discipline areas of existing subjects should be displayed in alphabetically order. The user will then enter a discipline code to which the program will respond by displaying any existing subject codes in that discipline. This procedure simplifies the user’s task of choosing subject codes that do not already exist, but does not prevent user mistake. Each subject code entered by the user should be checked. The user can enter any new subjects in that discipline (or indeed in other disciplines). The user should be given the choice of repeating the processing for other discipline areas.
• 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.

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

Task 2
Design a class named Octagon that extends GeometricObject class and implements the Comparable and Cloneable interface. Assume that all eight sides of the octagon are of equal size. The area can be computed using following formula: Area = (2 + 4√2) * side * side

Draw the UML diagram that involves Octagon, GeometricObjects, Comparable, and Cloneable. Write a test program that creates an Octagon object with side values 5 and display its area and perimeter. Create a new object using clone method and compare the two objects using compareTo method.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

* a Subject class, whose instances will represent the subjects for study at a university.
*/
public class Subject {
    // A subject will have a name, just a String,
    private String name;
    // a subject code, which is a six-character String
    private String code;

    public Subject(String code, String name) {
       this.name = name;
       Support support = new Support();
       if (!support.isValidCode(code)) {
            throw new IllegalArgumentException("Invalid subject code");
       }
       this.code = code;
    }

    /**
    * Getters will provide access to the code attributes.
    * @return code
    */
    public String getCode() {
       return code;
    }

    /**
    * Getters will provide access to the name attributes.
    * @return name
    */
    public String getName() {
       return name;
    }
   
    /**
    * accessor method called getDiscipline will return a
    * string containing the first three characters of the subject code
    * @return first three characters of the subject code
    */
    public String getDiscipline() {
       return code.substring(0, 3);
    }...
$60.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats