diff options
| author | Tyler Ferrari <69283684+Sowgro@users.noreply.github.com> | 2025-10-08 15:29:14 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-08 15:29:14 -0400 |
| commit | bf6b01e5005618e6ccdfb4217311a8f94dd5a0dd (patch) | |
| tree | 9d1a8af5e7829d0357ecfe8d0d9d51eb4c929091 /src/main/java/design/controller/userinput/menus/AddClubMenu.java | |
| parent | 701aba30fe05f65ab0e027f9d9aac0928d814560 (diff) | |
| parent | a20f2f027981ce9c7677b969be24c962c0029907 (diff) | |
| download | designproject-design-6-bf6b01e5005618e6ccdfb4217311a8f94dd5a0dd.tar.gz designproject-design-6-bf6b01e5005618e6ccdfb4217311a8f94dd5a0dd.tar.bz2 designproject-design-6-bf6b01e5005618e6ccdfb4217311a8f94dd5a0dd.zip | |
Merge pull request #9 from RIT-SWEN-262/lizzio-SelectClub
Lizzio select club
Diffstat (limited to 'src/main/java/design/controller/userinput/menus/AddClubMenu.java')
| -rw-r--r-- | src/main/java/design/controller/userinput/menus/AddClubMenu.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/main/java/design/controller/userinput/menus/AddClubMenu.java b/src/main/java/design/controller/userinput/menus/AddClubMenu.java new file mode 100644 index 0000000..ea18ed5 --- /dev/null +++ b/src/main/java/design/controller/userinput/menus/AddClubMenu.java @@ -0,0 +1,77 @@ +package design.controller.userinput.menus; + +import design.controller.userinput.Menu; +import design.controller.userinput.MenuOption; +import design.model.Club; +import design.model.Golfer; +import design.persistence.PersonalDatabase; +import design.runtime.Session; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Scanner; + +public class AddClubMenu extends Menu { + + @Override + public String getTitle() { + return "add a club"; + } + + @Override + public List<MenuOption> getMenuOptions() { + List<MenuOption> opts = new ArrayList<>(); + + opts.add(new MenuOption("create new club", () -> { + Golfer g = Session.getCurrentGolfer(); + if (g == null) { + System.out.println("No user loaded."); + new UserSettings().present(); + return; + } + + Scanner sc = new Scanner(System.in); + + System.out.print("Manufacturer: "); + String manufacture = sc.nextLine().trim(); + + System.out.print("Nickname: "); + String nickname = sc.nextLine().trim(); + + // Pick type + Club.ClubType[] types = Club.ClubType.values(); + System.out.println("Club type:"); + for (int i = 0; i < types.length; i++) { + System.out.printf("%d: %s%n", i + 1, types[i]); + } + + Club.ClubType type = null; + while (type == null) { + System.out.print("Select (1.." + types.length + "): "); + String line = sc.nextLine().trim(); + int idx = Integer.parseInt(line); + if (idx < 1 || idx > types.length) { + System.out.println("Out of range. Try again."); + continue; + } + type = types[idx - 1]; + } + + g.addClub(manufacture, nickname, type); + + // Add club to JSON + try { + PersonalDatabase.INSTANCE.updateGolfer(g); + System.out.println("Club added and saved."); + } catch (IOException e) { + throw new RuntimeException("Failed to save club", e); + } + new UserSettings().present(); + })); + + opts.add(new MenuOption("cancel", () -> new UserSettings().present())); + return opts; + } +} |
