Create subject class whose instances will represent subjects

Assignment Help JAVA Programming
Reference no: EM131507047

JAVA Assessment

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 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

In this task, you are required to provide complete class definitions and then create instances of various classes and use methods to perform various tests.

(a) Define an abstract class called Textbook with the following fields and methods:

• Fields: title, author, pages representing the title, author and the number of pages of a textbook for a given book respectively. Encapsulation should be used to protect these fields against intentional or accidental, direct modification

• Constructors: a no-args default constructor, and an overloaded constructor to initialise the fields to appropriate values when the instances of the class are created

• Methods: a toString() method to print a string representation of the objects, get and set methods to provide access to each of the three fields

(b) Define a subclass of the Textbook class called ProgrammingTextbook with the following additional field and methods:

• Field: language representing the particular language the programming textbook uses. Again, encapsulation should be used to protect this field against intentional or accidental, direct modification

• Constructors: a no-args default constructor, and an overloaded constructor to initialise the fields to appropriate values when the instances of the class are created

• Methods: a toString() method to print a string representation of the objects, additional get and set methods as required to provide access to the field

(c) Define another subclass of the Textbook class called EngineeringTextbook with the following additional field and methods:

• Field: subject representing the particular engineering subject the textbook teaches. Again, encapsulation should be used to protect this field against intentional or accidental, direct modification

• Constructors: a no-args default constructor, and an overloaded constructor to initialise the fields to appropriate values when the instances of the class are created

• Methods: a toString() method to print a string representation of the objects, additional get and set methods as required to provide access to the field

(d) Finally, define another class called TestTextbooks with a main() method to perform necessary testing for the classes defined in the previous sections. In the main method, write the code to create at least two objects of the ProgrammingTextbook class and at least two other objects of the EngineeringTextbook class. Create an ArrayList object to store references to these objects and then test various methods of the objects using loop(s) and methods as necessary.

Ensure that the program is appropriately documented throughout and thoroughly tested to demonstrate its correct operation.

Reference no: EM131507047

Questions Cloud

The mirror room of the amailienburg in nymphenburg : The Mirror Room of the Amailienburg in Nymphenburg is a great example of the Rococo style of art with its gentle pastels.
Determine life of alternative one for which aws are equal : Suppose that the capital investment of Alternative 1 is known with certainty. By how much would the estimate of capital investment for Alternative 2.
Security administrator for grocery stores : You've been hired as an information security administrator for Grocery Stores, Inc. Your duty is to assess the situation and determine the best course of action
Current industry support for wpan devices : Assess the current industry support for WPAN devices. Determine the technological advancements that are needed to support business strategy.
Create subject class whose instances will represent subjects : For this task you will create a Subject class, whose instances will represent the subjects for study at a university. Getters will provide access to attributes.
Critically analyze the procurement strategies : Procurement management (BUSS 1503)-Examine the ethical procurement issues of the selected organization and what could be the best practices and implementation.
Holds the vehicle identification number : Design a class name automobile that holds the vehicle identification number, make, model, and color of an automobile.
Perform a sensitivity analysis on the efficiency of pump a : An area can be irrigated by pumping water from a nearby river. Two competing installations are being considered.
Configuring servers for deployment : Before deploying Linux and Windows, you must identify the types of hardware present in most server systems, and configure the server storage.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Implement/update specific methods for the dfs of a graph

show the DFS order of vertices in the graph, and for each node, specify its parent node in the search (the node from which the currect node was reached). Moreover, display for each node the discovery and finishing time, to check that the Parenthesis ..

  Definition of a method named copy receives

Write the definition of a method named copy receives a reference to a Scanner object associated with a stream of input. The method reads all the Strings remaining to be read from the stream and displays them

  Create a book class which stores the information

You run a small library. Ask the user to provide information for several books. The information must include the author, title and publisher of each book.

  Create a application that will present a survey to customers

You have been asked by your manager to create a user-friendly application that will present a survey to your customers. The application will compile and analyze the results entered by the survey respondents.

  Write a java program that uses a search tree of strings

Write a Java program that uses a search tree of strings to sort text lines in alphabetic order. You may choose how you de?ne alphabetic order as long as there is some sense in the de?nition. You may also choose what kind of tree you use.

  Calculate the cross product of two numeric vectors function

Create a function that calculate the cross product of two numeric vectors Function Name: calcCrossProduct

  An elementary calculation yields the result

An elementary calculation yields the result that theoretically, the probability of turning up 7 when two dice are thrown is 1/6, or .166666. But what if more dice are thrown? If 3 dice are thrown, what is the probability that some 2 of three sum to 7..

  Pronouns, and prepositions

Type addKeyword(): for each word on each page, add to a (keyword, URLs) list or dictionary, excluding articles, pronouns, and prepositions. For example:

  Explain calculating average asdouble

EnhancedTestScoreApp.javacompiles, Uses += onscoreCountandscoreTotalfields, UsesMathclass methods to track minimum and maximum scores, Displays minimum and maximum scores at end, ChangedscoreTotaltoint, CastscoreCountandscoreTotaltodoublebefore calcu..

  Write a java program to read sequences of integers from a

write a java program to read sequences of integers from a text file build a binary search tree for each sequence by

  Create set methods for color and height, but not for price

Create a class for the business named Candle that contains data fields for color, height, and price. Create get methods for all three fields

  Design and implement a rmi-based client

In this assignment, you are requested to build a system which allows a school pupil to practise multiple choice tests in math. Design and implement a RMI-based Client / Server communication system in Java, which will do the following:

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd