This small project is geared to get you started on writing Object Oriented program using either Java or C++.
Create a class called Person that will hold information about a single individual. This class should have a data section that consists of the following:
|
Variable Name |
Data Type |
|
firstName |
string |
|
lastName |
string |
|
address |
string |
The Person class should have the following mutators:
setFirstName(string first);
setLastName(string last);
setAddress(string address);
The Person class should have the following accessors:
string getFirstName();
string getLastName();
string getAddress();
The Person class should have the following constructors:
Person(); - default
Person(string first, string last); - Set other fields to an empty string
Person(string first, string last, string address);
Note: You must use delegating constructors to eliminate duplicate code.
Main
Create an array which will hold 5 Person classes. Pass the array to a function called getPeople which will fill out the array with information about people taken from the keyboard. Create a second function called printPeople which will take the array of Person's and print it to the console window. Please format the output so that it can be easily read and understood.
import java.util.Scanner;
class Person {
private String firstName, lastName, address;
public Person() {
firstName = "";
lastName = "";
address = "";
}
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.address = "";
}
public Person(String firstName, String lastName, String address) {
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
}
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;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
public class Main {
public static void getPeople(Person[] persons) {
Scanner sc = new Scanner(System.in);
for (int i = 0; i<persons.length; i ++) {
persons[i] = new Person();
System.out.println("Enter the details for person " + (i + 1) + ": ");
System.out.println("Enter the first Name: ");
persons[i].setFirstName(sc.nextLine());
System.out.println("Enter the last Name: ");
persons[i].setLastName(sc.nextLine());
System.out.println("Enter the address: ");
persons[i].setAddress(sc.nextLine());
}
}
public static void printPeople (Person[] persons) {
System.out.println("The person details are: ");
for (int i = 0; i<persons.length; i ++) {
System.out.println("Details of person " + (i + 1) + " are: ");
System.out.println("First name: " + persons[i].getFirstName());
System.out.println("Last name: " + persons[i].getLastName());
System.out.println("Address: " + persons[i].getAddress());
}
}
public static void main(String[] args) {
Person persons[] = new Person[5];
getPeople(persons);
printPeople(persons);
}
}
This small project is geared to get you started on writing Object Oriented program using either...
help please
Program Requirements You are given 1 file: Lab1Tests.java. You need to complete 1 file: UWECPerson.java uWECPerson.java UWECPerson uwecld: int firstName: String lastName : String +UWECPerson(uwecld: int, firstName : String, lastName: String) +getUwecid): int setUwecld(uwecld: int): void +getFirstName): String +setFirstName(firstName: String): void getLastName): String setLastName(lastName: String): void +toString): String +equals(other: Object): boolean The constructor, accessors, and mutators behave as expected. The equals method returns true only if the parameter is a UWECPerson and all instance variables are equal. The...
Write in C++ 1. Use the following Person class (Person.cpp, Person.h). You will be writing Person objects to a random access file. --------------------- Person.cpp--------------------------------- // Class Person stores customer's credit information. #include <string> #include "Person.h" using namespace std; // default Person constructor Person::Person( int idValue, string lastNameValue, string firstNameValue, int AgeValue ) { setID( idValue ); setLastName( lastNameValue ); setFirstName( firstNameValue ); setAge( AgeValue ); } // end Person constructor // get id value int Person::getID() const { return id;...
Please implement the following problem in basic C++ code and
include detailed comments so that I am able to understand the
processes for the solution. Thanks in advance.
// personType.h
#include <string>
using namespace std;
class personType
{
public:
virtual void print() const;
void setName(string first, string last);
string getFirstName() const;
string getLastName() const;
personType(string first = "", string last = "");
protected:
string firstName;
string lastName;
};
// personTypeImp.cpp
#include <iostream>
#include <string>
#include "personType.h"
using namespace std;
void...
using C++ language!! please help me out with
this homework
In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private member attributes: lastName (string) firstName (string) exams (an integer array of fixed size of 4) average (double) Student1430 also has the following member functions: 1. A default constructor, which sets firstName and lastName to empty strings, and all exams and average to 0. 2. A constructor with 3 parameters:...
JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you created in the previous lab. In this lab, create a Student class with the following class variable: Student name: Name (Note: Name is a datatype) Student Id: String Create the getter and setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Complete...
I'm struggling to figure out how to do this problem in Java, any help would be appreciated: Create an application that uses a class to store and display contact information. Console: Welcome to the Contact List application Enter first name: Mike Enter last name: Murach Enter email: mike@murach.com Enter phone: 800-221-5528 -------------------------------------------- ---- Current Contact ----------------------- -------------------------------------------- Name: Mike Murach Email Address: mike@murach.com Phone Number: 800-221-5528 -------------------------------------------- Continue? (y/n): n Specifications Use a class named Contact to store the data...
Copy the entire program 9A and paste it into this one. Be sure to change the class name to 9B. Use descriptive variable names in camel-case with the first letter in lowercase. In the Student class, change the public attributes firstName and lastName to private ones. In the Student class, add getters and setters called getFirstName, getLastName, setFirstName, setLastName for the two attributes. In the Student class, add a constructor for the Student class that accepts two Strings, one parameter...
The object class should be a Student with the following attributes: id: integer first name: String last name: String write the accessors, mutators, constructor, and toString(). In your main test class you will write your main method and do the following things: Create an array of Student objects with at least 5 students in your array. Write a sort method that must be your original work and included in the main class. The sort method will sort based on student...
To conclude the project, use the UML diagram you created last week and create an application in Visual Studio named School. Once you have written the code, be sure and test it to ensure it works before submitting it. Below is the UML diagram for the basic class we created last week for your reference, but for this project be sure you use the one that you created last week. Good luck and be sure to get started early in...