In: Computer Science
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.
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 of the digits are entered, display the phone number and state it is not in Colorado.
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!
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.");
}
}
}