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

Write a Java program that asks the user for their age. If the age is greater tha

ID: 3884518 • Letter: W

Question

Write a Java program that asks the user for their age. If the age is greater than or equal to 18, print "Congratulations! You are an adult. You can vote". Otherwise print "You are not 18 yet. Enjoy your carefree days!".

What are the input values available to the program? What is the source of these values?

What other objects and methods are needed to read the input values?

How many variables are needed in this program? List their names and types.

What are some sample input values that we should test our program with?

Write a simple algorithm in plain English listing the steps that need to be followed to get the desired output.

Explanation / Answer

VoteTest.java

import java.util.Scanner;

public class VoteTest {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the user age: ");

int age = scan.nextInt();

if(age >= 18) {

System.out.println("Congratulations! You are an adult. You can vote");

} else {

System.out.println("You are not 18 yet. Enjoy your carefree days!");

}

}

}

Output:

Enter the user age:
20
Congratulations! You are an adult. You can vote

What are the input values available to the program? What is the source of these values?

Inteters are the input values avialble to the program that can be read from consolde by Scannner object.

What other objects and methods are needed to read the input values?

nextInt() method is used to read the integer value for age from Scanner

How many variables are needed in this program? List their names and types.

1 variable to hold age and 1 object to hold Scanner class

What are some sample input values that we should test our program with?

12 19 30 18 are the sample values

Write a simple algorithm in plain English listing the steps that need to be followed to get the desired output.

First enter the value once the prompt pop up like "Enter the user age: "

Give some value by keyboard then hit enter. So you can see the output.

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