Question

In: Computer Science

Program should be written in Java b) The computer program should prompt the user (You are...

Program should be written in Java

b) The computer program should prompt the user (You are the user) to enter the answers to the following questions: What is your city of birth? What is your favorite sport? If you could live anywhere in the world, where would you like to live? What is your dream vacation? Take this information and create a short paragraph about the user and output this paragraph. You may use the Scanner class and the System.out class or the JOptionPane classes as you desire. The purpose of this exercise is practice for concatenating Strings and producing String output.

Solutions

Expert Solution

Java Program:

import java.util.*;

class AnswerParagraph
{
   //Main method
   public static void main(String[] args)
   {
       //Creating Scanner object
       Scanner reader = new Scanner(System.in);
      
       //Reading answers from user
       System.out.print("\nWhat is your city of birth? ");
       String birthCity = reader.nextLine();
      
       System.out.print("What is your favorite sport? ");
       String favSport = reader.nextLine();
      
       System.out.print("If you could live anywhere in the world, where would you like to live? ");
       String livePlace = reader.nextLine();
      
       System.out.print("What is your dream vacation? ");
       String dreamVacation = reader.nextLine();
      
       //Constructing output string
       String output = "Hello All, I was born in " + birthCity + " but I would like to live in " + livePlace + ". My favorite sport was " + favSport + ". My dream vacation is " + dreamVacation;
      
       //Printing output string
       System.out.println("\n" + output + "\n");
   }
}

__________________________________________________________________________________________

Sample Run:


Related Solutions

Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
Write by hand a full java program that will prompt the user for the length and...
Write by hand a full java program that will prompt the user for the length and width of a square, calculate and display the area of that square rounded to the nearest tenth with an appropriate message.
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
Write a program that calculates the salary of employees. The program should prompt the user to...
Write a program that calculates the salary of employees. The program should prompt the user to enter hourly rate and number of hours of work a day. Then, the program should display the salary daily, bi-weekly (5 days a week), and monthly. Sample program: Enter your hourly rate: >>> 20 Enter how many hours you work a day: >>> 8 Your daily salary is: $160 Your bi-weekly salary is: $1600 Your monthly: $3200
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
(b) You will write a program that will do the following: prompt the user enter characters...
(b) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘Q’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘Q’. Example input mJ0*5/]+x1@3qcxQ The ‘Q’ should be included when computing the statistics properties of the input. Since characters are integers...
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
Answer in JAVA Write a program that would prompt the user to enter an integer. The...
Answer in JAVA Write a program that would prompt the user to enter an integer. The program then would displays a table of squares and cubes from 1 to the value entered by the user. The program should prompt the user to continue if they wish. Name your class NumberPowers.java, add header and sample output as block comments and uploaded it to this link. Use these formulas for calculating squares and cubes are: square = x * x cube =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT