Question: can someone combine these two codes for them to work. thanks! import java.util.Scanner; public class PersonTest { public static void main(String[] args) { Scanner input

can someone combine these two codes for them to work. thanks!

import java.util.Scanner;

public class PersonTest { public static void main(String[] args) { Scanner input = new Scanner(System.in); String firstName = new String(); String lastName = new String(); // read first name System.out.print(" Please enter a first name: "); firstName = input.nextLine(); // read last name System.out.print("Please enter a last name: "); lastName = input.nextLine(); Person name = new Person(firstName, lastName); // call constructor System.out.println("First name : " +name.getFirstName()); System.out.println("Last name : "+ name.getLastName()); System.out.println("Full name : " + name.toString()); } }

//////////////////////////////////////////////////////////////////////////////////////////

public class Person { private String firstName; //store the first name private String lastName; //store the last name //Default constructor; //Initialize firstName and lastName to empty string. //Postcondition: firstName = ""; lastName = ""; public Person() { firstName = ""; lastName = ""; } //Constructor with parameters //Set firstName and lastName according to the parameters. //Postcondition: firstName = first; lastName = last; public Person(String first, String last) { setName(first, last); } //Method to output the first name and last name //in the form firstName lastName public String toString() { return (firstName + " " + lastName); } //Method to set firstName and lastName according to //the parameters //Postcondition: firstName = first; lastName = last; public void setName(String first, String last) { firstName = first; lastName = last; } //Method to return the firstName //Postcondition: the value of firstName is returned public String getFirstName() { return firstName; } //Method to return the lastName //Postcondition: the value of lastName is returned public String getLastName() { return lastName; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!