Skip to content

Commit

Permalink
feat(5.5.1): finish Person.java
Browse files Browse the repository at this point in the history
  • Loading branch information
101zh committed Nov 15, 2023
1 parent 20040c7 commit 0f97068
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/Unit5/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package Unit5;

// Have to get rid of package statement

public class Person {
String firstName;
String lastName;
int age;
String ssn;

public Person(String firstName, String lastName, int age, String ssn) {
this.firstName = firstName;
this.lastName = lastName;
this.age = Math.abs(age);
this.ssn = ssn;
}

public String toString() {
String toStrString = "SSN: " + ssn + "\n" +
"\tName: " + firstName + " " + lastName + "\n" +
"\tAge: " + age;

return toStrString;
}
}
29 changes: 29 additions & 0 deletions src/test/java/Unit5/runner_Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package Unit5;

// Have to get rid of package statement

import java.util.Scanner;

public class runner_Person
{

public static void main(String[] args)
{

Scanner scan = new Scanner(System.in);

System.out.println("Enter the person's first name:");
String firstName = scan.nextLine();
System.out.println("Enter the person's last name:");
String lastName = scan.nextLine();
System.out.println("Enter the person's age:");
int age = scan.nextInt();
scan.nextLine();
System.out.println("Enter the person's social security number:");
String ssn = scan.nextLine();

System.out.println();
Person person = new Person(firstName, lastName, age, ssn);
System.out.println(person);
}
}

0 comments on commit 0f97068

Please sign in to comment.