import java.util.*;
public class java
{
private String m_name;
private String m_game;
private int m_score;
private int m_played;
public java( String name, String game, int score, int played)
{
m_name = name;
m_game = game;
m_score = score;
m_played = played;
}
public String getName()
{
return m_name;
}
public String getgame()
{
return m_game;
}
public int getscore()
{
return m_score;
}
public int getplayed()
{
return m_played;
}
public String toString()
{
return "name: " + m_name + ", game: " + m_game +
", Score: " + m_score + ", played: " + m_played;
}
public static void main(String[] args)
{
ArrayList<java> students = new ArrayList<java>();
Scanner input = new Scanner(System.in);
int menuChoice = 4;
do {
System.out.println("\t\t\tStudnent's Gaming Records");
System.out.println("\t1. Add Student\t\t2. View Students \t3. Averages\t4. Exit");
try {
System.out.println("Enter a choice: ");
menuChoice = Integer.parseInt(input.nextLine());
} catch (NumberFormatException e) {
continue;
}
if (menuChoice==1)
{
System.out.println("Player Name");
String name = input.nextLine();
System.out.println("Game:");
String game = input.nextLine();
int played = -1;
do {
try {
System.out.println("Time Played:");
played = Integer.parseInt(input.nextLine());
} catch (NumberFormatException e) {
System.out.println("Enter a number!");
continue;
}
} while (played <= 0);
int score = -1;
do {
try {
System.out.println("Score:");
score = Integer.parseInt(input.nextLine());
} catch (NumberFormatException e) {
System.out.println("Enter a number!");
continue;
}
} while (score <= 0);
java student = new java(name, game, score, played);
students.add(student);
System.out.println(student);
} else if (menuChoice==2) {
System.out.println("Students:");
for (java student : students)
{
System.out.println(student);
}
}
} while (menuChoice<3);
System.out.println("swag");
}
}
This is my code so far, it works excellent but I'm having a hard time trying to figure out a few things firstly, when a user press's 1 I want the game entry, score entry and played entry to loop indefinitely until the user types "quit" when done so in the "2" section of my menu it will displayed all the games, scores and times the user has entered under one username. My second question is how can i check for empty strings? Thanks all in advance.