1 / 2100%
import java.io.*;
import java.util.*;
// local variables, can be accessed anywhere from the main method
char input1 = 'Z';
String inputInfo;
String firstName, lastName, sport;
int date, month, year;
String city, state;
String line = new String();
// Athlete object to beused for this assignment
Athlete athlete1 = new Athlete();
printMenu();
// Create a Scanner object to read user input
Scanner scan = new Scanner(System.in);
do // will ask for user input
{
System.out.println("What action would you like to perform?");
line = scan.nextLine();
if (line.length() == 1) {
input1 = line.charAt(0);
input1 = Character.toUpperCase(input1);
// matches one of the case statement
switch (input1) {
case 'A': // Add Project
System.out.print("Please enter an athlete
information:\n");
System.out.print("Enter the athlete's first
name:\n");
firstName = scan.nextLine();
System.out.print("Enter the athlete's last
name:\n");
lastName = scan.nextLine();
System.out.print("Enter the athlete's sport:\n");
sport = scan.nextLine();
System.out.print("Enter the athlete's birth
date:\n");
date = Integer.parseInt(scan.nextLine());
System.out.print("Enter the athlete's birth
month:\n");
month = Integer.parseInt(scan.nextLine());
System.out.print("Enter the athlete's birth
year:\n");
year = Integer.parseInt(scan.nextLine());
System.out.print("Enter the athlete's birth
city:\n");
city = scan.nextLine();
System.out
.print("Enter the athlete's birth
state/country:\n");
state = scan.nextLine();
athlete1.setFirstName(firstName);
athlete1.setLastName(lastName);
public class Assignment4 {
public static void main(String[] args) {
athlete1.setSport(sport);
athlete1.setBirthInfo(date, month, year, city,
state);
break;
case 'D': // Display Project
System.out.print(athlete1);
break;
case 'Q': // Quit
break;
case '?': // Display Menu
printMenu();
break;
default:
System.out.print("Unknown action\n");
break;
}
} else {
System.out.print("Unknown action\n");
}
} while (input1 != 'Q' || line.length() != 1);
}
/** The method printMenu displays the menu to a user **/
public static void printMenu() {
System.out.print("Choice\t\tAction\n" + "------\t\t------\n"
+ "A\t\tAdd Athlete\n" + "D\t\tDisplay Athlete\n"
+ "Q\t\tQuit\n" + "?\t\tDisplay Help\n\n");
}
}
Powered by TCPDF (www.tcpdf.org)
Students also viewed