Question

In: Computer Science

Write a program that prompts the user for their first and lastname. Display the first...

  1. Write a program that prompts the user for their first and last name. Display the first initial of their first name and their last name to the user.

  2. Ask the user to input a phone number.

  3. The program checks which part of Colorado a phone number is from using the values below.

  4. If the second digit of the phone number is one of the below digits, print the phone number and which part of Colorado it is from. If none of the digits are entered, display the phone number and state it is not in Colorado.

  5. If the number is in Estes Park, the user should see: phone number + “is in Estes Park, it is time to go pick up your new Corgi puppy!”

If the second digit of a phone number is:

0 = Boulder

1 = Colorado Springs

2 = Denver

7 = Estes Park

Sample output:

Please enter your first and last name: Ollie Biscuit

Hello, O Biscuit! //displays first initial and last name

Please enter a phone number:

Your phone number is: xxx-xxx-xxxx. Your number is not in Colorado.

OR

Your phone number is: xxx-xxx-xxxx. Your number is in Denver.

OR

Your phone number is: xxx-xxx-xxxx is in Estes Park, it is time to go pick up your new Corgi puppy!

Solutions

Expert Solution

source code:

package helo;

import java.util.Scanner;

public class file {

public static void main(String[] args) {
  
    int position=0;
   Scanner in=new Scanner(System.in);
String name = in.nextLine();
  
  
System.out.print(name.charAt(0)+" ");
  
for(int i=0;i {
   if(name.charAt(i)==32)
   { position=i;
   break;}
     
   }

for(int i=position+1;i {
    System.out.print(name.charAt(i));
    }
  
System.out.println("\nEnter phone number : ");
String phone=in.nextLine();
  
if(phone.charAt(1)=='0')
{ //checking number is in which state
   System.out.println("Your phone number is:"+phone+". Your number is in Boulder.");
}
else if(phone.charAt(1)=='1')
{
   System.out.println("Your phone number is:"+phone+". Your number is in Colorado Springs.");
}
else if(phone.charAt(1)=='2')
{
   System.out.println("Your phone number is:"+phone+". Your number is not Denver.");
}
else if(phone.charAt(1)=='7')
{
   System.out.println("Your phone number is :"+phone+"is in Estes Park, it is time to go pick up your new Corgi puppy");
}
else {

   System.out.println("Your phone number is:"+phone+". Your number is not in COlorado.");
}
  
  
}
}


Related Solutions

Write the pseudocode that prompts the user for their first and last name. Display the first...
Write the pseudocode that prompts the user for their first and last name. Display the first initial of their first name and their last name to the user. Ask the user to input a phone number. The program checks which part of Colorado a phone number is from using the values below. If the second digit of the phone number is one of the below digits, print the phone number and which part of Colorado it is from. If none...
Write a program to use Math methods to calculate and display the followings: Prompts the user...
Write a program to use Math methods to calculate and display the followings: Prompts the user to enter an angle, in degrees, and then display the angle in radians and the Sine of the angle. Prompts the user to enter a positive integer and calculates the square root of the number. Computational thinking: Your program must check if it is a positive number. If a negative number is entered, it must ask for another number until the positive number is...
Write a program that prompts the user to enter two characters and display the corresponding major...
Write a program that prompts the user to enter two characters and display the corresponding major and year status. The first character indicates the major. And the second character is a number character 1, 2, 3, 4, which indicates whether a student is a freshman, sophomore, junior, or senior. We consider only the following majors: B (or b): Biology C (or c): Computer Science I (or i): Information Technology and Systems M (or m): Marketing H (or h): Healthcare Management...
Write a MIPS assembly program that prompts the user first for a string, then for a...
Write a MIPS assembly program that prompts the user first for a string, then for a character. The program should then search the string for the character and print out the number of times the character appears in the string. You can use as many restrictions as you want, just be sure to list them. You must allocate space in the .data segment of your program for the user string.
Write a program that prompts the user enter a word, and determines the first half and...
Write a program that prompts the user enter a word, and determines the first half and second half of the word. Print the first and second half of the word on different lines. Sample runs of the program are shown below. Note: If the word is an odd number of letters, the first half should contain fewer letters (as shown in sample run #2) SAMPLE PROGRAM RUN #1                     Enter a word: carrot First half: car Second half: rot SAMPLE PROGRAM...
Write a program that prompts the user to input their first name from the keyboard and...
Write a program that prompts the user to input their first name from the keyboard and stores them in the variable "firstName". It does the same for last name and stores it in the variable "lastName". It then uses strcat to merge the two names, separates them by a space and stores the full name into a string variable called "fullName". In the end, the program must print out the string stored within fullName. ANSWER IN C LANGUAGE ! You...
Write a C# program that prompts the user to enter in three values. The first indicates...
Write a C# program that prompts the user to enter in three values. The first indicates a starting (whole number positive) value, the second an ending value and the third an increase value. output a table of squares and square roots, every increase value from the start to the end value. For instance if the values were: start 3, end 20, and increase 4. the table would consist of 3,7,11,15,19 and their squares and square roots. Please include all code...
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT