Question

In: Computer Science

Write program#1 upload .java file. #1 Write a java program that prompts the user for input...

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?

Solutions

Expert Solution

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.


Related Solutions

Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
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...
Question 1: Write a Java program that prompts the user to input a file name (existing...
Question 1: Write a Java program that prompts the user to input a file name (existing text file), then calculate and display the numbers of lines in that file. Also calculate and display the length of the longest line in that file. For example, if the input file has the following lines: Hello This is the longest line Bye The output should be: The file has 3 lines. The longest line is line 2 and it has 24 characters. Test...
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
1. Write a program that prompts the user for a filename, then reads that file in...
1. Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba Need Help with this be done in only PERL. Please use "reverse"
(JAVA) Create a program that prompts the user for an age input. The program defines the...
(JAVA) Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program. Age Age Group 0 Baby 1-3 Toddler 4-11 Child 12-17 Teenager 18-21 Young Adult 22-64 Adult 65+ Senior Negative Number Invalid Input Sample Input Enter an age: 18 Sample Output: You are a young adult. Sample Input Enter an age: 29 Sample Output: You are an adult. Sample...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
Write a program that prompts the user to enter a file name, then opens the file...
Write a program that prompts the user to enter a file name, then opens the file in text mode and reads names. The file contains one name on each line. The program then compares each name with the name that is at the end of the file in a symmetrical position. For example if the file contains 10 names, the name #1 is compared with name #10, name #2 is compared with name #9, and so on. If you find...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT