Page 53 - CTS - CSA TP - Volume 2
P. 53
COMPUTER SOFTWARE APPLICATION - CITS
3 Inside the main method:
• It creates a new Scanner object named scanner to read input from the console.
• It prompts the user to enter their age by displaying the message “Enter your age: “.
• It reads the integer input provided by the user using the nextInt() method of the Scanner class and stores it in
the variable age.
4. The program then checks whether the entered age is greater than or equal to 18, the legal voting age in many
countries.
• If the age is 18 or older, it prints “You are eligible to vote.”
• If the age is less than 18, it prints “You are not eligible to vote yet.”
5. Finally, the scanner object is closed to release system resources after it’s no longer needed.
Output:
TASK 3: Grading system
// Grading System
import java.util.Scanner;
public class GradingSystem {
public static void main(String[] args) {
// Create a Scanner object to read input from the console
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter the student’s score
System.out.print(“Enter the student’s score: “);
// Read the integer input provided by the user
int score = scanner.nextInt();
// Determine the grade based on the score and print the result
if (score >= 90) {
System.out.println(“Grade: A”);
} else if (score >= 80) {
System.out.println(“Grade: B”);
38
CITS : IT & ITES - Computer Software Application - Exercise 85