Explain getters and setters in java

Assignment Help JAVA Programming
Reference no: EM13940188

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.

Reference no: EM13940188

Questions Cloud

Prepare a personal analysis of the payout options for bob : Prepare a personal analysis of the payout options for Bob, Chad and Dylan. Designate the preferred option for each individual and explain why
Political-social-cultural media and economic trends : Write an essay that discusses whether or not in the 21st century a 4th World Australia exists, defining 4th world and describing the political, social, cultural media and economic trends that you feel influence your objective and professional pers..
Find units that goslin must sell to earn operating income : Prepare an income statement for Goslin Company for last year. Calculate the break-even point in units. Calculate the units that Goslin must sell to earn operating income of $9,900 next year.
What is the annualized forward premium : The one-year forward rate of the British pound is quoted at $1.60, and the spot rate of the British pound is quoted at $1.63. What is the annualized forward premium or discount of the pound? You are a speculator who sells a put option on Canadian dol..
Explain getters and setters in java : A constructor will allow a name and a new, validated subject code to be provided when a new subject is created.
Compare organizational structures of correctional agencies : Criminal justice organizations are structured differently based upon the mission of the organization. Compare and contrast the organizational structures of correctional agencies, law enforcement agencies, and courts.
Invest using discount brokers : Many young professionals choose to invest using discount brokers. Give two reasons why you might follow their lead. Also, list two reasons why using a discount broker may not be the best choice.
How a risc cycle is obtained from the von neumann cycle : Draw the Von Neumann Cycle and explain the basic function carried out in each state. Explain clearly how a RISC cycle is obtained from the Von Neumann cycle.
Invested in twelve different stocks that have combined value : Steve has invested in twelve different stocks that have a combined value today of $121,300. Fifteen percent of that total is invested in Wise Man Foods. The 15 percent is a measure of which one of the following?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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