Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem #2: Reading input You will write a program from scratch that accomplishe

ID: 3748429 • Letter: P

Question

Problem #2: Reading input You will write a program from scratch that accomplishes the following: . Create a new Java class file named simpleInput . Create a Scanner object to read from the console Prompt the user for their first name on one line (use println for prompt) User will enter the name on the next line, you should read in the name value . Print a message that says hello to the user (i.e., "Hello ") on the next line . Skip a line, then prompt the user for the year they were born on a line by itsefl (use println for prompt) . Read in the value (which will be on its own line) Print the year they were born on the next line . Calculate and print the age the user will be this year on the next line * Declare a constant for average life expectancy, set its value to 76.9 . Print the percentage of their expected life they've lived on the next line Skip a line, then prompt the user for what they believe the value of Pi to be on a line by itself (use println) . Read in the value (which will be on its own line) . Print the value they entered on the next line Print how close they are to the actual value of Pi (22 divided by 7), print just the numerical difference

Explanation / Answer

Here's the java code I have prepared for this problem statement:

/************ SimpleInput.java *******************/

import java.util.Scanner;

import java.util.Calendar;

public class SimpleInput

{

public static final double avg_life_exptecy = 76.9;

public static final double PI = 3.14159265358979323846;

public static void main(String[] args) {

System.out.print("What is your name? ");

Scanner scanner = new Scanner(System.in);

String inputString = scanner.nextLine();

System.out.println("Hello, "+inputString);

inputString=null;

System.out.println("What year wear you born? ");

inputString = scanner.nextLine();

int year_born=Integer.parseInt(inputString);

System.out.println(year_born);

inputString=null;

int current_year=Calendar.getInstance().get(Calendar.YEAR);

int age = (current_year - year_born);

System.out.println(age);

float percentage = (float)((age*100)/avg_life_exptecy);

System.out.println(percentage);

System.out.println(" What is the value of pi? ");

inputString = scanner.nextLine();

double value_of_pi=Double.parseDouble(inputString);

System.out.println(value_of_pi);

double pi_diff = (PI - value_of_pi);

System.out.println(pi_diff);

}

}

Please ensure the java file and class name (i.e. SimpleInput) remains the same; otherwise, it would throw an error.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote