Question

In: Computer Science

A.Write a program that prompts for and reads the user’s first and last name (separately).Then print...

A.Write a program that prompts for and reads the user’s first and last name (separately).Then print the initials with the capital letters. (Note that we do not expect that inputs from users are case-sensitive. For example, if the user’s input of the first name is robert and of the last name is SMITH, you should print R.S.)

B.Write a program that creates and prints a random phone number of the form XXX-XXX-XXXX. Include the dashed in the output. Do not let the first three digit contain an 8 or 9 (but don’t be more restrictive than that), and make sure that the second set of three digits is not greater than 655. Hint: Think through the easiest way to construct the phone number. Each digit does not have to be determined separately.

-use java

Solutions

Expert Solution

Answer 1:

import java.util.Scanner;

public class Example1 {
public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   //reading first name and last name
   System.out.println("Enter first name");
   String f=sc.next();
   System.out.println("Enter last name");
   String l=sc.next();
   //appending first char from each string and converting into uppercase
   String in = f.toUpperCase().charAt(0)+"."+l.toUpperCase().charAt(0);
   System.out.println(in);
}
}

Answer 2:

import java.util.Random;

public class RandomPhone {
   public static void main(String[] args) {
       String phone = "";
       Random r = new Random();
       String firstThree = "";
       // generating first three numbers until it has other 8 and 9
       while (true) {
           firstThree = "" + (r.nextInt(899) + 100);
           if (!firstThree.contains("8") && !firstThree.contains("9"))
               break;
       }
       phone = firstThree;
       // generating the next 3 numbers less than 655
       phone = phone + "-" + (r.nextInt(555) + 100);
       // generating last 4 digits
       phone = phone +"-"+ (r.nextInt(9999) + 1000);
       System.out.println(phone);
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other.
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
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 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 program that prompts for and reads in the two side lengths of a right...
Write a program that prompts for and reads in the two side lengths of a right triangle (floating point numbers) and then calls a float-valued function, hypot1, that calculates and returns the length of the hypotenuse of the triangle. The program then displays the two side lengths and the hypotenuse length. Note: The hypot1 function returns the hypotenuse length – it does not display it; the function should not contain any cout nor cin statements. Math review: Recall that for...
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"
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.
C++ Write a program that asks a teacher to input a student’s first name, last name,...
C++ Write a program that asks a teacher to input a student’s first name, last name, and four test scores. The program should find the average of the four test scores and should then write the following information to a file named “students.txt” last_name first_name average A student's first name of “XX” should be used as a sentinel value and no numeric grades less than 0 or greater than 100 should be accepted.  The program should then read the information in...
C++ Change the program to take user input for first name and last name for five...
C++ Change the program to take user input for first name and last name for five employees. Add a loop to read the first name and last name. // EmployeeStatic.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <string> #include <iostream> #include <string> using namespace std; class Employee { public:    Employee(const std::string&, const std::string&); // constructor    ~Employee(); // destructor    std::string getFirstName() const; // return first name    std::string getLastName() const; // return...
Write a program that utilizes a Professor class. A professor has a first name, last name,...
Write a program that utilizes a Professor class. A professor has a first name, last name, affiliation, easiness grade, and a helpfulness grade. Grades range from 1 (lowest) to 5 (highest). The Professor class has two constructors. The first constructor initiates the object with just the first name, the last name, and the affiliation. The default value for easiness and helpfulness grade is 3. The second constructor initiates the object using the first name, the last name, the affiliation, and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT