-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFootballSystem.java
More file actions
198 lines (163 loc) · 8.92 KB
/
FootballSystem.java
File metadata and controls
198 lines (163 loc) · 8.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.mycompany.project2;
/**
*
* @author alihabibi
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;
/**
*
* @author alihabibi
*/
public class FootballSystem {
public static void main(String[] args) throws FileNotFoundException, IOException {
ArrayList<PlayersInfo> players = new ArrayList<PlayersInfo>();
//adding players to the list
players.add(new PlayersInfo("Ali","Striker"," injured"));
players.add(new PlayersInfo("John","Midfielder","Recovering.."));
players.add(new PlayersInfo("Farred","Defender","Ready"));
//making a new team
Team team = new Team("team1",players);
//calling the practiceday class within the dates class
dates prac = new practiceday("08/11/24");
//calling the gameday class within the dates class
dates gameday = new gameday("06/12/24");
// linup generator
LineUpGenerator gen = new LineUpGenerator();
gen.generator();
Scanner scan = new Scanner(System.in);
int quit = 0;
while (quit == 0) {
try {
System.out.println("");
System.out.println("Choose an option");
System.out.println("1. Team Roaster");
System.out.println("2. Team Practice day");
System.out.println("3. Team game day");
System.out.println("4. Team game/practice day booking");
System.out.println("5. Team game/practice day cancellation");
System.out.println("6. Check booking details");
System.out.println("7. Show more information about team game time and the number of people");
System.out.println("8. Quit");
int input = scan.nextInt();
switch (input) {
case 1:
System.out.println("Current lineup:");
System.out.println(team.getRoster());
System.out.println("Do you want to choose a player from the available players? (Type 'y')\nTo register a player, type 'n'");
System.out.println("To remove a player from the roaster (type 'r')");
String newplayer = scan.next();
if ("y".equalsIgnoreCase(newplayer)) {
System.out.println("What position does the player require? (Defender, Midfielder, Striker, GoalKeeper)");
String position = scan.next();
if ("Defender".equalsIgnoreCase(position)) {
PlayersInfo newPlayer = new PlayersInfo("Yamin", "Defender", "Recovering(will be back in 2 months)");
players.add(newPlayer);
System.out.println("Updated Roaster:");
System.out.println(team.getRoster() + newPlayer + " has been added to the team");
} else if ("Striker".equalsIgnoreCase(position)) {
PlayersInfo newPlayer = new PlayersInfo("Brian", "Striker", "Ready");
players.add(newPlayer);
System.out.println("Updated Roaster:");
System.out.println(team.getRoster() + newPlayer + " has been added to the team");
} else if ("GoalKeeper".equalsIgnoreCase(position)) {
PlayersInfo newPlayer = new PlayersInfo("Jay", "GoalKeeper", "Ready");
players.add(newPlayer);
System.out.println("Updated Roaster:");
System.out.println(team.getRoster() + newPlayer + " has been added to the team");
} else if ("Midfielder".equalsIgnoreCase(position)) {
PlayersInfo newPlayer = new PlayersInfo("Sena", "Midfielder", "Ready");
players.add(newPlayer);
System.out.println("Updated Roaster:");
System.out.println(team.getRoster() + newPlayer + " has been added to the team");
} else {
System.out.println("Invalid position entered.");
}
} else if ("n".equalsIgnoreCase(newplayer)) {
System.out.println("What is the name of the player?");
String name = scan.next();
System.out.println("What is the position of the player?");
String position = scan.next();
PlayersInfo newPlayer = new PlayersInfo(name, position, null);
players.add(newPlayer);
System.out.println("Updated Roaster:");
System.out.println(team.getRoster() + newPlayer + " has been added to the team");
} else if("r".equalsIgnoreCase(newplayer))
{
System.out.println("What is the name of the player?");
String name = scan.next();
System.out.println("What is the position of the player?");
String position = scan.next();
team.removePlayer(name, position);
}
else {
System.out.println("Invalid input. Please enter 'y' or 'n'.");
}
break;
case 2:
System.out.println(prac);
break;
case 3:
System.out.println(gameday);
break;
case 4:
System.out.println("Enter the date for booking (MM/dd/yy):");
String bookingDate = scan.next();
System.out.println("Enter the number of people for the booking:");
int numPeople = scan.nextInt();
BookingInfo bookingInfo = new BookingInfo(bookingDate, numPeople);
team.bookGameOrPracticeDay(bookingInfo,true);
System.out.println("Booking successful.");
break;
case 5:
System.out.println("Enter the date for cancellation (MM/dd/yy):");
String cancellationDate = scan.next();
team.cancelGameOrPracticeDay(cancellationDate,false);
System.out.println("Cancellation successful.");
break;
case 6:
System.out.println(team.getBookingDetails());
break;
case 7:
System.out.println("Team game time: " + gameday.getDate());
System.out.println("Number of people: " + team.getNumPlayers());
break;
case 8:
quit = 1;
System.out.println("Quitting the program...");
break;
default:
System.out.println();
System.out.println("*Invalid input. Please choose a valid option.*");
break;
}
} catch (InputMismatchException e) {
System.out.println();
System.out.println("*Invalid input. Please enter a numeric value.*");
scan.nextLine();
}
}
// Write data to a file
String content ="";
for (PlayersInfo player : players)
{
content += player.getName()+ "\n";
}
String filename = "textfile.txt";
String roster = content;
FileIO.writeToFile(filename, roster);
//Read data from a file
String display = FileIO.readFromFile(filename);
System.out.println(display);
System.out.println("That is the final Roster");
}
}