In: Computer Science
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code. Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip code "0" with "N", replace "7" with "J". Use the String Class to make all the values upper case. Use the String Class to determine the length of full_name. Print on first line full_name and length of full_name. Print all on second line mailing address, including zip_string?
Save the program in a file names upload.java to run
___________________________________________________________________________
//Importing Scanner class for taking user input
import java.util.Scanner;
public class upload{
public static void main(String[] args){
Scanner input = new
Scanner(System.in);
//prompting user for input and
saving inputs as variables
//java.util.Scanner.nextLine()
method scans the next token of the input as String.
System.out.println("\n\nEnter First
name:\n");
String fName =
input.nextLine();
System.out.println("\nEnter Last
name:\n");
String lName =
input.nextLine();
System.out.println("\nEnter
City:\n");
String city =
input.nextLine();
System.out.println("\nEnter
State:\n");
String state =
input.nextLine();
System.out.println("\nEnter
Zipcode:\n");
//Integer.toString() method
converts integers to string.
//java.util.Scanner.nextInt()
method scans the next token of the input as an int.
String zipcode =
Integer.toString(input.nextInt());
//concatenating first name and last
name
String full_name = fName + " " +
lName;
//replacing 0 with N and 7 with
J in zipcode.
zipcode = zipcode.replace('0',
'N');
zipcode = zipcode.replace('7',
'J');
//convert all the values to
upper case
full_name =
full_name.toUpperCase();
city = city.toUpperCase();
state = state.toUpperCase();
zipcode =
zipcode.toUpperCase();
//finding the length of full
name(including space between first and last name)
int full_name_length =
full_name.length();
System.out.println("\n\nFull
Name: " + full_name + " Length of Full Name: " +
full_name_length);
System.out.println("\nMailing
address: " + city + ", " + state + ", " + zipcode + ". " +
"\n\n");
}//end of main() method
}//end of upload class
___________________________________________________________________________
Sample output:
If you have any doubt, please comment. Upvote if satisfied.