Question

In: Computer Science

Code needed in Java The purpose of the application is to generate some reports about the...

Code needed in Java
The purpose of the application is to generate some reports about the people of the university. So a user of the application should be able to view information about the people in the university and generate summaries. As in implementation these are separated into two major categories, employee and students, we will be implementing these classes.  


The system should have three classes: Person, Employee and Student.Employees and students are subclasses of persons and therefore, they inherit some fields and methods from the superclass Person. What Employee class has as an extra is a field called job which is a String value that indicates the position of the employee at the university. The possible values are ‘Faculty’ and ‘Staff’ and the rest of the input should be rejected. Another significant field is UIN (you may assume it to be an integer).Students also have a similar structure. A field called level, gives information regarding the student. Possible values are ‘Undergraduate’ and ‘Graduate’ and the rest of the input should be rejected. Also A number should be implemented (you may assume A number to be a string).  
Once you create these classes write your test class with main method.  


The output of such an application would look like:  

Person’s first name is Triss, last name is Merigold. She is 25 years old.
Person’s first name is Sigismund, last name is Dijkstra. He is 37 years old. His UIN is 793942 and serves the university as a staff.
Person’s first name is Keira, last name is Metz. She is 19 years old. Her A-number is A021318 and she is an undergraduate student

Solutions

Expert Solution

// Test.java
class Person
{
    String firstName;
    String lastName;
    int age;
    String gender;

    Person(String firstName, String lastName, int age, String gender)
    {
        gender = gender.toLowerCase();
        if(gender != "male" && gender != "female")
            throw new IllegalArgumentException("gender should be either male or female.");
        this.firstName = firstName;
        this.lastName = lastName;
        this.age = age;
        this.gender = gender;
    }

    public String toString()
    {
        String out = "Person's first name is " + this.firstName + ", last name is " + this.lastName + ".";
        if(this.gender == "male")
            out += " He ";
        else
            out += " She ";
        out += "is " + this.age + " years old.";
        return out;
    }
}

class Employee extends Person
{
    int UIN;
    String job;

    Employee(String firstName, String lastName, int age, String gender, int UIN , String job)
    {
        super(firstName, lastName, age, gender);
        if(job.toLowerCase() != "faculty" && job.toLowerCase() != "staff")
            throw new IllegalArgumentException("job should be either faculty or staff.");
        this.UIN = UIN;
        this.job = job;
    }

    public String toString()
    {
        String out = super.toString();
        if(this.gender == "male")
            out += " His ";
        else
            out += " Her ";
        out += "UIN is " + this.UIN + " and serves the university as a " + this.job + ".";
        return out;
    }
}

class Student extends Person
{
    String A_number;
    String level;

    Student(String firstName, String lastName, int age, String gender, String A_number, String level)
    {
        super(firstName, lastName, age, gender);
        if(level.toLowerCase() != "graduate" && level.toLowerCase() != "undergraduate")
            throw new IllegalArgumentException("level should be either graduate or undergraduate.");
        this.A_number = A_number;
        this.level = level;
    }

    public String toString()
    {
        String out =  super.toString();
        if(this.gender == "male")
            out += " His ";
        else
            out += " Her ";
        out += "A-number is " + this.A_number + " and";
        if(this.gender == "male")
            out += " he ";
        else
            out += " she ";
        out += "is an " + this.level + " student.";
        return out;
    }
}

public class Test
{
    public static void main(String args[])
    {
        try
        {
            Person p = new Person("Triss", "Merigold", 25, "female");
            Employee e = new Employee("Sigismund", "Dijkstra", 37, "male", 793942, "staff");
            Student s = new Student("Keira", "Metz", 19, "female", "A021318", "undergraduate");
            System.out.println(p.toString());
            System.out.println(e.toString());
            System.out.println(s.toString());
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
}

Output


Related Solutions

The code is needed in Java. There are many ways to design a solution to this...
The code is needed in Java. There are many ways to design a solution to this problem but you are evaluated on meeting the specific specifications as given in this quiz. Use proper statement indentation and meaningful variable names in the code. (3 points) Place a multi-line comment (not multiple single line comments) giving a description of what this application does before the class header. Include your name and the date with the description. (2 points) Output spacing, formatting, and...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls:...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls: A Label control with the following text displayed: "First Number:" A Label control with the following text displayed: "Second Number:" An empty TextField control beside the First Number label. An empty TextField control beside the Second Number label. Five buttons: Button 1 labeled + Button 2 labeled - Button 3 labeled * Button 4 labeled / Button 5 labeled = An empty Label control...
It is required to develop an application in Java to perform some operations of a bank....
It is required to develop an application in Java to perform some operations of a bank. The application will have the following classes: Class called Person having following data fields (private): firstName (String), lastName(String), gender(char), cpr(long), mobile(String) and following methods: Constructor having 5 parameters to initialize all data fields, Set and get methods for all data fields, toString method to return String equivalent of all data fields, Abstract class called Account having following data fields(protected): accountHolder(Person), ccountNum(long), balance(double)and following methods:...
Java Script Ask the user for a Fahrenheit temperature Write the code needed to convert a...
Java Script Ask the user for a Fahrenheit temperature Write the code needed to convert a Fahrenheit temperature into a Celsius temperature. Use an alert box to show the result Ask the user for a Celsius temperature Write a function to convert from Celsius to Fahrenheit; use an alert box to show the results Decide on two other conversions (meters to feet, pounds to kilos, other) Ask the user for numbers to be converted; be sure to tell them what...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used to hold the rectangle’s width....
Write a Java application that accepts a bar code as a command line parameter and prints...
Write a Java application that accepts a bar code as a command line parameter and prints out the ZIP code. Assume that the bar code uses the symbols "|" and ":" for the long and short bars, respectively. Provide warnings on errors in the bar code specifying what exactly is wrong. The bar code input should be in the format specified in Problem 1, including the pair of the full bars at the beginning and at the end. Important: The...
given an array, write code to scan the array for a particular purpose . use java
given an array, write code to scan the array for a particular purpose . use java
Java Code: Write an application that takes in user input. (Name, Age, and Salary) ------ Write...
Java Code: Write an application that takes in user input. (Name, Age, and Salary) ------ Write an application that includes a constructor, user input, and operators.
A question about exceptions, the language is JAVA. The purpose is writing a program that reads...
A question about exceptions, the language is JAVA. The purpose is writing a program that reads a string from the keyboard and tests whether it contains a valid time. Display the time as described below if it is valid, otherwise display a message as described below. The input date should have the format hh:mm:ss (where hh = hour, mm = minutes and ss = seconds in a 24 hour clock , for example 23:47:55). Here are the input errors (Exceptions)...
Write a Java application, and an additional class to represent some real-world entity such as a...
Write a Java application, and an additional class to represent some real-world entity such as a technology item, an animal, a person, a vehicle, etc. Keep in mind that a class is a model in code of something real or imagined, which has attributes (member variables) and behaviors (member methods). The class will: Create a total of 5 member variables for the class, selecting the appropriate data types for each field. For example, a class to represent a lamp might...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT