Write in Java program that requires the user to enter their age. Your program shall then
determine if the individual is old enough to drive (age >=18). If the user is younger that 18, your program should tell them to wait for n years, where n is the number of years until they are 18. If the user is 18 or above, your program shall then require the user to enter their name and
surname in two (2) different variables. Having entered their name and surname, you program shall then print the details of the user. Ensure the following, the name of the user shall always start with a capital letter. All the letters of their surname shall be in capital letters.
A and B shall be displayed regardless of how the user had entered their details
import java.util.Scanner;
public class License {
public String firstUpperCase(String word){
if(word == null || word.isEmpty()) return ""; //или return word;
return word.substring(0, 1).toUpperCase() + word.substring(1);
}
public void Check(Scanner in, License license){
System.out.print("Enter your age: ");
int age = in.nextInt();
if(age < 18) {
System.out.println("Please, wait " + (18 - age) + " years");
}
if(age >= 19){
System.out.print("Enter your first name: ");
String firstName = in.next();
System.out.print("Enter your last name: ");
String lastName = in.next();
firstName = license.firstUpperCase(firstName);
lastName = license.firstUpperCase(lastName);
System.out.println("Your first name: " + firstName + "\nYour last name: " + lastName);
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
License license = new License();
license.Check(in, license);
}
}
Comments
Leave a comment