Assignemnt #46 and Age Messages 3
Code
/// Name: Marco Correa
/// Period: 5
/// Program Name: AgeMessages3
/// File Name: AgeMessages3.java
/// Date Finished: 11/19/2015
import java.util.Scanner;
public class AgeMessages3
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String name;
StringBuilder sb = new StringBuilder();
int age;
System.out.print( "Your name: " );
name = keyboard.next();
System.out.print( "Your age: " );
age = keyboard.nextInt();
if ( age < 16 )
{
sb.append("You can't drive, ").append(name)
.append(".");
}
else if ( age >= 16 && age < 18 )
{
sb.append("You can drive but not vote, ").append(name)
.append(".");
}
else if ( age >= 18 && age < 25 )
{
sb.append("You can vote but not rent a car, ").append(name)
.append(".");
}
else
{
sb.append("You can pretty much do anything, ").append(name)
.append(".");
}
System.out.println(sb);
}
}
Picture of the output