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 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 :...
jgrasp environment, java write a complete program that prompts the user to enter their first name,...
jgrasp environment, java write a complete program that prompts the user to enter their first name, middle name, and last name (separately). print out thier name and initials, exactly as shown: your name is: John Paul Chavez your initials are: J. P. C. use string method chartAt() to extract the first (zero-th) character from a name(the name is a string type): username.charAt(0). thank you.
Write a C++ program that prompts the user for the radius of a circle and then...
Write a C++ program that prompts the user for the radius of a circle and then calls inline function circleArea to calculate the area of that circle. It should do it repeatedly until the user enters -1. Use the constant value 3.14159 for π Sample: Enter the radius of your circle (-1 to end): 1 Area of circle with radius 1 is 3.14159 Enter the radius of your circle (-1 to end): 2 Area of circle with radius 2 is...
Write a program which: Prompts the user for a positive integer >= 0 Validates the user...
Write a program which: Prompts the user for a positive integer >= 0 Validates the user input to ensure it is a positive integer >= 0 Allocate (dynamically) an array big enough for the data. Load the array with random numbers ranging in value from1 to 100 Display the elements of the array (unsorted) Display the elements of the array (sorted) Display the average Display the median Display the mode, if none, display appropriate message RESTRICTIONS No global variables No...
Write a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
Write a program which prompts the user for the year of their birth, and which then...
Write a program which prompts the user for the year of their birth, and which then calculates their age (ignoring the month/day). Split the program into `main`, a "prompt for year" function which tests to make sure the user's input is a valid year, and a "calculate age" function which performs the actual calculation. (You can assume the current year is 2017.) for my intro to c++ class
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT