Question

Question 1 (24 Marks] 1. (4 marks) Write an immutable Person class in Java which provides the following. • Two attributes: la

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Points to consider:

  1. We need to declare the instance variables.
  2. Then function for getters and setters are to be declared.
  3. The constructor for the class has to be defined.

Code


public class Person{
   // Instance Variables
   private String firstName, lastName;
   // Parameterized Constructor
   public Person(String firstName, String lastName) {
       super();
       this.firstName = firstName;
       this.lastName = lastName;
   }
   // Getter for First Name
   public String getFirstName() {
       return firstName;
   }
   // Setter for First Name
   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }
   // Getter for last Name
   public String getLastName() {
       return lastName;
   }
   // Setter for last name
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }
   // To String function for the Person Class
   @Override
   public String toString() {
       return "Person [firstName=" + firstName + ", lastName=" + lastName + "]";
   }   
}

So above is the Person Class.

Being a Chegg expert, I am obliged to do only one question at a time.
I hope you understand.
Thanks

Add a comment
Know the answer?
Add Answer to:
Question 1 (24 Marks] 1. (4 marks) Write an immutable Person class in Java which provides...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Do the following a. Write a class Student that has the following attributes: - name:...

    1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date. Student(String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • Write a java program to create a student file which includes first name, last name, and...

    Write a java program to create a student file which includes first name, last name, and GPA. Write another Java program to open the students file. Display the students list and calculate the average GPA of the class.  

  • Write a Java program which will store, manipulate, and print student registration information. As part of...

    Write a Java program which will store, manipulate, and print student registration information. As part of the solution, identify the following classes: Student Admissions. The class Student must have the following fields – Name, Address, Id number, Courses, and Date, where: Name is a user defined class comprising of at minimum first name and last name. Address is a user defined class comprising of fields - street, city, state, and zip code. Date is a predefined class in the java.util...

  • (10 marks) Question 1 Class Definitions la) (5 marks) Write information on Java class called IdentityCard...

    (10 marks) Question 1 Class Definitions la) (5 marks) Write information on Java class called IdentityCard to represent the the identity card of a member of an organisation. For example a UWA student card. Include brief comments in your class necessary, but full Javadoc is not required. State any a. definition as assumptions you make. The class should have: four fields that capture the person's name, identity number, photo, and whether the person is a current member of the organisation;...

  • You are asked to build and test the following system using Java and the object-oriented concepts ...

    You are asked to build and test the following system using Java and the object-oriented concepts you learned in this course: Project (20 marks) CIT College of Information technology has students, faculty, courses and departments. You are asked to create a program to manage all these information's. Create a class CIT to represents the following: Array of Students, each student is represented by class Student. Array of Faculty, each faculty is represented by class Faculty. Array of Course, each course...

  • Given a class called Student and a class called Course that contains an ArrayList of Student....

    Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called getDeansList() as described below. Refer to Student.java below to learn what methods are available. I will paste both of the simple .JAVA codes below COURSE.JAVA import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{     /** collection of Students */     private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

  • what is the solution for this Java problem? Generics Suppose you need to process the following...

    what is the solution for this Java problem? Generics Suppose you need to process the following information regarding Students and Courses: A Student has a name, age, ID, and courseList. The class should have a constructor with inputs for setting name, ID and age. The class should have setters and getters for attributes name, ID and age, and a method addCourse, removeCourse, printSchedule. courseList: use the generic class ArrayList<E> as the type of this attribute addCourse: this method takes as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT