Answer to Question #315310 in Java | JSP | JSF for Dunga

Question #315310

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

1
Expert's answer
2022-03-21T14:08:08-0400
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);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS