Question

Create a new project and call it Pr8. The project shall have two classes, MainClass and Person. Person shall have the followi
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program Code Screenshot :

1 2 Main.java class Person //Instance variables private int id; private String firstName, lastName; 3 4 5 6 7 8 //Argumented

44 ► 45 46 class Main public static void main(String[] args) { Person p1 = new Person(1, James, Anderson); Person p2 = ne

Sample Output :

Run: 个 Main C:\Program Files\Java\jdk-13\bin\java.exe [id : 1, firstName : James, lastName : Anderson] [id : 2, firstName :

Program Code to Copy

class Person{
    //Instance variables
    private int id;
    private String firstName, lastName;

    //Argumented constructor
    public Person(int id, String firstName, String lastName) {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    //Getters and Setters
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Override
    public String toString() {
        return "[id : "+id+", firstName : "+firstName+", lastName : "+lastName+"]";
    }
}

class Main{
    public static void main(String[] args) {
        Person p1 = new Person(1, "James", "Anderson");
        Person p2 = new Person(2,"Tim","Paine");
        System.out.println(p1);
        System.out.println(p2);
    }
}
Add a comment
Know the answer?
Add Answer to:
Create a new project and call it Pr8. The project shall have two classes, MainClass and...
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
  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • Create a C++ project with 2 classes, Person and Birthdate. The description for each class is...

    Create a C++ project with 2 classes, Person and Birthdate. The description for each class is shown below: Birthdate class: private members: year, month and day public members: copy constructor, 3 arguments constructor, destructor, setters, getters and age (this function should return the age) Person class: private members: firstName, lastName, dateOfBirth, SSN public members: 4 arguments constructor (firstName, lastName, datOfBirth and SNN), destructor and printout Implementation: - use the separated files approach - implement all the methods for the 2...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • answer in c# console application. File l/O Create a Person class (firstName, lastName, phoneNumber, gender (Use...

    answer in c# console application. File l/O Create a Person class (firstName, lastName, phoneNumber, gender (Use radioButtons for gender in the GUI) ) Create a List<Person> Create a GUI that will collect the Person information from the user and have 3 buttons: Add, Display, Read. Add button Add the just created person to List<Person>, and append to a text file Display button > print out all persons currently in the List<Person> in a label in a visually attractive way Read...

  • In c# So far, you have created object-oriented code for individual classes. You have built objects...

    In c# So far, you have created object-oriented code for individual classes. You have built objects from these classes. Last week, you created a UML for new inherited classes and objects. Finally, you have used polymorphism. When you add abstraction to this mix, you have the “4 Pillars of OOP.” Now, you begin putting the pieces together to create larger object-oriented programs. Objectives for the project are: Create OO classes that contain inherited and polymorphic members Create abstracted classes and...

  • have to create five different functions above and call it in the main fucntion. Project Exam...

    have to create five different functions above and call it in the main fucntion. Project Exam Statistics A CIS 22A class has two midterm exams with a score between 0 and 100 each. Fractional scores, such as 88.3 are not allowed. The students' ids and midterm exam scores are stored in a text file as shown below // id exam1 exam2 DH232 89 92 Write a program that reads data from an input file named exams.txt, calculates the average of...

  • Create a console application project and solution called “ConsoleWorkWithData.” using C# Create the following variables with...

    Create a console application project and solution called “ConsoleWorkWithData.” using C# Create the following variables with data type: a. FirstName: string data type b. LastName: string data type c. Student ID: int data type d. BirthDate: data time data type e. Grade: decimal data type Write all values in these variables to the screen in this format: a. --------------------------------------------------------- b. My name is Rieser Angie c. I’m a new student, and this is my first program d. ************************************** e. My...

  • Assighment. Creaung Java Classes with methods Note: If you have not yet completed this unit's Discussion,...

    Assighment. Creaung Java Classes with methods Note: If you have not yet completed this unit's Discussion, it is best to complete it before you begin this Assignment As studied in the Discussion, it is important to design a test plan prior to creating a class, as it will help reduce coding problems. In this unit's Assignment, you create, compile, and execute a class containing methods. Be sure to use best coding practices, such as creating a test plan, before you...

  • Hw08FinalProjectStudentList.txt: (Data structure is Array List) 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is

    Hw08FinalProjectStudentList.txt: (Data structure is Array List) 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is going to evaluate your overall knowledge of the Java Programming. You shall implement a program which can store and retrieve student list. The program has a menu that you can take input from console, and the user can choose between the items. The program data is in the HwO8FinalProjectStudentList.txt file. Required Items: 1. The program must show a menu to user and ask the user...

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