Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose you’re given the first name, the last name, the school attended and the

ID: 3864606 • Letter: S

Question

Suppose you’re given the first name, the last name, the school attended and the graduation year. You are to display two lines of messages on the screen: Name: Jane Doe Background: Graduated from ASU 5 years ago The text in blue are to be replaced with appropriate data Complete the code in the next slide

Suppose you’re given the first name, the last name, the school attended and the graduation year.

You are to display two lines of messages on the screen:

Name: Jane Doe

Background: Graduated from ASU 5 years ago

The text in blue are to be replaced with appropriate data

Complete the code in the next slide

//    Assignment: Class Activity 1-2.1

//      File Name: StringDemo.java

//             Name:

//           Topic: Character Strings

//     Description: Practice concatenating and displaying Strings

import java.util.*;

public class StringDemo {

               public static void main (String[] args) {

                              String firstName, lastName, school;

                              int year;

                              Scanner scan = new Scanner(System.in);

                              System.out.println("Enter your first and last names: ");

                              firstName=scan.next();

                              lastName=scan.next();

                              System.out.println("Enter your school and graduation year: ");

                              school=scan.next();

                              year = scan.nextInt();

                              scan.close();

                              // Insert your code here

               }

}

Name: Jane Doe

Background: Graduated from ASU 5 years ago

Explanation / Answer

StringDemo.java

import java.util.*;
public class StringDemo {
public static void main (String[] args) {
String firstName, lastName, school;
int year;
Scanner scan = new Scanner(System.in);
System.out.println("Enter your first and last names: ");
firstName=scan.next();
lastName=scan.next();
System.out.println("Enter your school and graduation year: ");
school=scan.next();
year = scan.nextInt();
scan.close();
// Insert your code here
System.out.println("Name: "+firstName+" "+lastName);
System.out.println("Background: Graduated from "+school+" "+year+" years ago ");

}
}

Output:

Enter your first and last names:
Jane
Doe
Enter your school and graduation year:
ASU
5
Name: Jane Doe
Background: Graduated from ASU 5 years ago