generated from microsoft/vscode-remote-try-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |