diff --git a/src/main/java/org/codedifferently/BandGigManager.java b/src/main/java/org/codedifferently/BandGigManager.java new file mode 100644 index 0000000..d02d2ed --- /dev/null +++ b/src/main/java/org/codedifferently/BandGigManager.java @@ -0,0 +1,211 @@ +package org.codedifferently; + +import java.util.ArrayList; +import java.util.Collections; + +//stores main abstraction of modifier methods we call when we want to update/view/adjust fields in the program +public class BandGigManager { + + //arraylists used because we need a collection to store objects that is not fixed in size + //needed to be able to easily add and remove objects from list, and access them with indexing + //for this reason ArrayList was a good choice + private final ArrayList gigs; + private final ArrayList songCatalog; + private final ArrayList defaultBandMembers; + + //constructor, no paramaters needed + public BandGigManager() { + gigs = new ArrayList<>(); + songCatalog = new ArrayList<>(); + defaultBandMembers = new ArrayList<>(); + defaultBandMembers.add("Alex"); + defaultBandMembers.add("Jonny"); + defaultBandMembers.add("Bailey"); + defaultBandMembers.add("Matty"); + } + + //add gig to ArrayList + public void addGig(Gig gig) { + gigs.add(gig); + } + + //getter to return list of gigs + public ArrayList getGigs() { + return gigs; + } + + //find gig at index in ArrayList + public Gig findGigByIndex(int index) { + if (index >= 0 && index < gigs.size()) { + return gigs.get(index); + } + return null; + } + + //update gig complete boolean + public boolean markGigCompleteByIndex(int index) { + Gig gig = findGigByIndex(index); + + if (gig == null) { + return false; + } + + gig.markCompleted(); + return true; + } + + //display all gigs in array list + public void viewAllGigs() { + if (gigs.isEmpty()) { + System.out.println("No gigs available."); + return; + } + + //for loops are going to allow us to iterate through the list + for (int i = 0; i < gigs.size(); i++) { + System.out.println((i + 1) + ". " + gigs.get(i)); + System.out.println(); + } + } + + //display all gigs that aren't completed + public void viewUpcomingGigs() { + boolean found = false; + + for (int i = 0; i < gigs.size(); i++) { + if (!gigs.get(i).isCompleted()) { + System.out.println((i + 1) + ". " + gigs.get(i)); + System.out.println(); + found = true; + } + } + + if (!found) { + System.out.println("No upcoming gigs."); + } + } + + //display all gigs that are completed + public void viewCompletedGigs() { + boolean found = false; + + for (int i = 0; i < gigs.size(); i++) { + if (gigs.get(i).isCompleted()) { + System.out.println((i + 1) + ". " + gigs.get(i)); + System.out.println(); + found = true; + } + } + + if (!found) { + System.out.println("No completed gigs."); + } + } + + //sum payments of the gigs + public double calculateTotalEarnings() { + double total = 0.0; + + //enhanced for loop to iterate through list, only add to sum if gig is completed + for (Gig gig : gigs) { + if (gig.isCompleted()) { + total += gig.getPayment(); + } + } + + return total; + } + + //add song to catalog list + public void addSongToCatalog(String song) { + songCatalog.add(song); + } + + //get entire song catalog list object + public ArrayList getSongCatalog() { + return songCatalog; + } + + //not used + public void addDefaultBandMember(String member) { + defaultBandMembers.add(member); + } + + //not used, getter + public ArrayList getDefaultBandMembers() { + return defaultBandMembers; + } + + //clear lineup and add members in defaultBandMembers to gig lineup + public void applyDefaultLineup(Gig gig) { + gig.getLineup().clear(); + gig.getLineup().addAll(defaultBandMembers); + } + + + public void generateSetlistForGig(Gig gig, int numberOfSongs) { + if (songCatalog.isEmpty()) { + return; + } + + ArrayList tempSongs = new ArrayList<>(songCatalog); + + //randomly reorder elements in collection tempSongs + Collections.shuffle(tempSongs); + + gig.clearSetlist(); + + for (int i = 0; i < numberOfSongs && i < tempSongs.size(); i++) { + gig.addSong(tempSongs.get(i)); + } + } + + //takes gig index to add generated setlist to specific gig + public boolean generateSetlistForGigByIndex(int index, int numberOfSongs) { + Gig gig = findGigByIndex(index); + + if (gig == null || gig.isCompleted() || songCatalog.isEmpty()) { + return false; + } + + generateSetlistForGig(gig, numberOfSongs); + return true; + } + + //add song to setlist array list, if/else locks out gig if completed + public boolean addSongToGigSetlist(int gigIndex, String song) { + Gig gig = findGigByIndex(gigIndex); + + if (gig == null || gig.isCompleted()) { + return false; + } + + gig.addSong(song); + return true; + } + + //remove song from setlist array list in gig, if/else locks out gig if completed + public String removeSongFromGigSetlist(int gigIndex, int songIndex) { + Gig gig = findGigByIndex(gigIndex); + + if (gig == null || gig.isCompleted()) { + return null; + } + + return gig.removeSongAtIndex(songIndex); + } + + //display gig info, lineup and setlist for a gig + public void viewGigDetails(int index) { + Gig gig = findGigByIndex(index); + + if (gig == null) { + System.out.println("Invalid gig selection."); + return; + } + + System.out.println(gig); + System.out.println("Lineup: " + gig.getLineup()); + System.out.println("Setlist: " + gig.getSetlist()); + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Gig.java b/src/main/java/org/codedifferently/Gig.java new file mode 100644 index 0000000..de0590e --- /dev/null +++ b/src/main/java/org/codedifferently/Gig.java @@ -0,0 +1,141 @@ +package org.codedifferently; + +import java.util.ArrayList; + +public class Gig { + //used private fields to limit accessibility as much as possible + //fulfilling encapsulation principles + private String date; + private Venue venue; + private double payment; + private boolean completed; + private ArrayList lineup; + private ArrayList setlist; + + //constructor no arguments + public Gig() { + lineup = new ArrayList<>(); + setlist = new ArrayList<>(); + completed = false; //completed defaults to false, gig has to be manually logged as complete + } + + //alternate constructor + public Gig(String date, Venue venue, double payment) { + this.date = date; + this.venue = venue; + this.payment = payment; + this.completed = false; + this.lineup = new ArrayList<>(); + this.setlist = new ArrayList<>(); + } + + //getter + public String getDate() { + return date; + } + + //setter + public void setDate(String date) { + this.date = date; + } + + public Venue getVenue() { + return venue; + } + + public void setVenue(Venue venue) { + this.venue = venue; + } + + public double getPayment() { + return payment; + } + + public void setPayment(double payment) { + this.payment = payment; + } + + public boolean isCompleted() { + return completed; + } + + public void setCompleted(boolean completed) { + this.completed = completed; + } + + public ArrayList getLineup() { + return lineup; + } + + public void setLineup(ArrayList lineup) { + this.lineup = lineup; + } + + public ArrayList getSetlist() { + return setlist; + } + + public void setSetlist(ArrayList setlist) { + this.setlist = setlist; + } + + + //add to arraylist + public void addBandMember(String member) { + lineup.add(member); + } + + //remove from arraylist + public void removeBandMember(String member) { + lineup.remove(member); + } + + public void addSong(String song) { + setlist.add(song); + } + + //remove all from setlist arraylist + public void clearSetlist() { + setlist.clear(); + } + + //update completed boolean to true + public void markCompleted() { + completed = true; + } + + //tells us whether completed boolean is true or false + public String getStatus() { + if (completed) { + return "Completed"; + } + return "Scheduled"; + } + + //update index of lineup arraylist + public void swapBandMember(String oldMember, String newMember) { + int index = lineup.indexOf(oldMember); + + if (index != -1) { + lineup.set(index, newMember); + } + } + + //remove item at index in setlist arraylist + public String removeSongAtIndex(int index) { + if (index >= 0 && index < setlist.size()) { + return setlist.remove(index); + } + return null; + } + + @Override + public String toString() { + return "Date: " + date + + "\nVenue: " + venue.getName() + + "\nCity: " + venue.getCity() + + "\nPayment: $" + payment + + "\nStatus: " + getStatus(); + } +} +// \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 435139b..cc4193a 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -4,14 +4,12 @@ // click the icon in the gutter. public class Main { public static void main(String[] args) { - //TIP Press with your caret at the highlighted text - // to see how IntelliJ IDEA suggests fixing it. - System.out.printf("Hello and welcome!"); - for (int i = 1; i <= 5; i++) { - //TIP Press to start debugging your code. We have set one breakpoint - // for you, but you can always add more by pressing . - System.out.println("i = " + i); + //all user input logic stored in UI + UI ui = new UI(); + ui.startProgram(); + + + } } -} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/README.md b/src/main/java/org/codedifferently/README.md new file mode 100644 index 0000000..2ae3e35 --- /dev/null +++ b/src/main/java/org/codedifferently/README.md @@ -0,0 +1,115 @@ +Team Alex, Fred, and Henrietta + + +# BandGigManager: +Bands struggle to track gigs, payments, players, setlists and venues, this application allows them to easily track everything in one spot. + +## THE PLAN + +Our 3 sprints took place over 1 day, March 9th. +During sprint planning, we divided responsibilities as follows: + +Alex was responsible for initial app setup with classes and core methods. +Fred was responsible for input handling and user interfaces(menus) and README.md . +Henrietta assisted with leaving code comments explaining logic and other discretionary touch-ups. + +We plan to allow users to do the following: +- Add a new gig +- Store and view venue information +- Track payment for each gig +- Mark a gig as completed +- View upcoming gigs +- View total earnings from completed gigs +- Adjust the lineup for a specific gig +- Add songs to a gig’s setlist +- Generate a setlist for a gig from a song catalog +- View full gig details, including venue, status, lineup, and setlist + + +## THE PLAN: + +- Venue +This class will store information about a venue. +Expected fields: +venue name +city +capacity +contact name +contact email + + +- Gig +This class will represent one performance. +Expected fields: +gig ID +event name +date +venue +payment +completion status +lineup +setlist + +- BandGigManager +This class will manage the overall system. +Expected responsibilities: +store all gigs +add gigs +search for a gig +display upcoming gigs +calculate total earnings +store default band members +store a song catalog +generate setlists for gigs (weighted setlists) + +- UI() +This class handles menus and user prompts with Scanner to keep Main method clean. +This class will run the command-line interface.+ +Show the menu +Get user input with Scanner +Call methods from BandGigManager +Keep the program running until the user exits + +- Main() +Call UI to run program. + +## THE BUILD +-Venue +This class does store information about venues, but we simplified it and removed fields +like contact name and contact email. It wasn't helpful for our MVP. + +-Gig +This class successfully stores info about gigs, but we cut down on some of the fields for simplicity. +We were not able to implement gigID or eventName. This is something we can look at implementing in our next iteration, +as we still think these are important identifiers to have. + +-BandGigManager +We managed to mostly accomplish everything we set out to do with this class. We were +also able to incorporate features like band lineup adjustment. One thing that we missed which we could improve, +pertaining to the bandGigManager and Gig is using actual date/times for tracking gigs. We could have +displayed these to the user in chronological order (instead of order of first insertion), but this is +something we could accomplish with more time. Additionally, we could've incorporated weighted setlists, which is something +we wanted to try to tackle during planning. We also might consider using a set for setlist (since it can't contain duplicates). + +-UI +Completely implemented, handles all user input and runs main program loop. We ran into issues with menu complexity, +we tried to resolve this by creating submenus with similar options grouped together, rather than one giant menu. + + +We consistently had issues with using nextInt in our scanner, as well as trying to refactor the code +to be robust against bad input. The nextInt thing was a token issue where it would skip our next input, so we just added +an extra nextLine() wherever that appeared. For input handling, we imported helper functions from another project and +incorporated them into our code. + +## THE REFLECTION +-Our program is a complete MVP, functionally accomplishing everything that we wanted to. The code and structure is pretty +well organized, however we can incorporate more detailed comments. There are also leftover getter/setter methods that were +never actually used in the project, that are still hanging around. These could be removed or given a use in the program. We also +mentioned some additional features we could add in BandGigManager. +We used a lot of Encapsulation throughout the project, included in Gig, Venue, and BandGigManager +classes which have private fields being accessed by getters and setters. There was polymorphism used, with multiple overloaded functions. +Abstraction was used in a conceptual sense with class design, but not implemented with abstract classes or interfaces. +Inheritance wasn't directly used, there are no subclasses extending parent classes. + +This program reinforced concepts we've previously implemented and really helped with the process of designing software from scratch, +rather than following a pre-scripted scenario. \ No newline at end of file diff --git a/src/main/java/org/codedifferently/UI.java b/src/main/java/org/codedifferently/UI.java new file mode 100644 index 0000000..bf0b8ce --- /dev/null +++ b/src/main/java/org/codedifferently/UI.java @@ -0,0 +1,463 @@ +package org.codedifferently; + +import org.codedifferently.helpers.InputHandler; + +import java.util.Scanner; + +//houses all user input logic + helper functions for updating gig info +public class UI { + + private final BandGigManager bgm = new BandGigManager(); + private final Scanner sc = new Scanner(System.in); + + //loop to ask for and collect user input, loop used so it keeps program running until user quits + public void startProgram() { + boolean running = true; + + while (running) { + System.out.println("\n============= BAND GIG MANAGER ============="); + System.out.println("1. Gig Scheduling"); + System.out.println("2. Song and Setlist Maintenance"); + System.out.println("3. Band Lineup"); + System.out.println("4. Calculate Total Earnings"); + System.out.println("0. Exit"); + System.out.println("===================================================="); + System.out.print("Select option: "); + + //uses helper functions in InputHandler to validate user input + int choice = InputHandler.handleIntegerInput(sc); + + switch (choice) { + case 1: + showGigMenu(); + break; + case 2: + showSongMenu(); + break; + case 3: + adjustGigLineupMenu(); + break; + case 4: + System.out.println("Total earnings: $" + bgm.calculateTotalEarnings()); + break; + case 0: + running = false; + System.out.println("Closing Band Gig Manager..."); + break; + default: + System.out.println("Invalid selection. Please try again."); + } + } + } + + //subdivision to help make menus cleaner + private void showGigMenu() { + boolean running = true; + + do { + System.out.println("\n============== GIG MENU =============="); + System.out.println("1. Create New Gig"); + System.out.println("2. View Upcoming Gigs"); + System.out.println("3. View Completed Gigs"); + System.out.println("4. View All Gigs"); + System.out.println("5. View Gig Details"); + System.out.println("6. Mark Gig Completed"); + System.out.println("0. Exit"); + System.out.println("======================================"); + System.out.print("Select option: "); + + int choice = InputHandler.handleIntegerInput(sc); + + switch (choice) { + case 1: + addNewGig(); + break; + case 2: + bgm.viewUpcomingGigs(); + break; + case 3: + bgm.viewCompletedGigs(); + break; + case 4: + bgm.viewAllGigs(); + break; + case 5: + viewGigDetails(); + break; + case 6: + markGigComplete(); + break; + case 0: + running = false; + break; + default: + System.out.println("Invalid selection. Please try again."); + } + } while (running); + } + + //subdivision to help make menus cleaner + private void showSongMenu() { + boolean running = true; + + do { + System.out.println("\n========== SONG / SETLIST MENU =========="); + System.out.println("1. Add Song To Catalog"); + System.out.println("2. View Song Catalog"); + System.out.println("3. Generate Setlist For A Gig"); + System.out.println("4. View Setlist For A Gig"); + System.out.println("5. Add Song Manually To A Gig Setlist"); + System.out.println("6. Remove Song From A Gig Setlist"); + System.out.println("0. Exit"); + System.out.println("========================================="); + System.out.print("Select option: "); + + int choice = InputHandler.handleIntegerInput(sc); + + switch (choice) { + case 1: + addSongToCatalog(); + break; + case 2: + viewSongCatalog(); + break; + case 3: + generateSetlist(); + break; + case 4: + viewGigSetlist(); + break; + case 5: + addSongToGigSetlist(); + break; + case 6: + removeSongFromGigSetlist(); + break; + case 0: + running = false; + break; + default: + System.out.println("Invalid selection. Please try again."); + } + } while (running); + } + + //subdivision to help make menus cleaner + private void adjustGigLineupMenu() { + if (bgm.getGigs().isEmpty()) { + System.out.println("No gigs available."); + return; + } + + System.out.println("Select a gig to adjust lineup for:"); + bgm.viewAllGigs(); + + int gigIndex = promptForGigIndex("Enter gig number: "); + if (gigIndex == -1) { + return; + } + + Gig gig = bgm.findGigByIndex(gigIndex); + + if (gig.isCompleted()) { + System.out.println("Cannot adjust lineup for a completed gig."); + return; + } + + boolean editing = true; + + while (editing) { + System.out.println("\n===== LINEUP MENU ====="); + System.out.println("Gig: " + gig.getDate() + " at " + gig.getVenue().getName()); + System.out.println("Current Lineup: " + gig.getLineup()); + System.out.println("1. Apply Default Lineup"); + System.out.println("2. Add Band Member"); + System.out.println("3. Remove Band Member"); + System.out.println("4. Swap Band Member"); + System.out.println("0. Return to Main Menu"); + System.out.print("Select option: "); + + int choice = InputHandler.handleIntegerInput(sc); + + switch (choice) { + case 1: + bgm.applyDefaultLineup(gig); + System.out.println("Default lineup applied to this gig."); + break; + case 2: + System.out.print("Enter member to add: "); + String memberToAdd = InputHandler.handleStringInput(sc); + gig.addBandMember(memberToAdd); + System.out.println("Band member added to this gig."); + break; + case 3: + System.out.print("Enter member to remove: "); + String memberToRemove = InputHandler.handleStringInput(sc); + gig.removeBandMember(memberToRemove); + System.out.println("Band member removed from this gig."); + break; + case 4: + System.out.print("Enter member to replace: "); + String oldMember = InputHandler.handleStringInput(sc); + + System.out.print("Enter new member: "); + String newMember = InputHandler.handleStringInput(sc); + + gig.swapBandMember(oldMember, newMember); + System.out.println("Band member swapped for this gig."); + break; + case 0: + editing = false; + break; + default: + System.out.println("Invalid selection."); + } + } + } +//helper function to get gig being referenced by user + private int promptForGigIndex(String prompt) { + System.out.print(prompt); + int gigNumber = InputHandler.handleIntegerInput(sc); + + Gig gig = bgm.findGigByIndex(gigNumber - 1); + if (gig == null) { + System.out.println("Invalid gig selection."); + return -1; + } + + return gigNumber - 1; + } + +//function to collect user input needed to create a new gig + private void addNewGig() { + System.out.print("Enter name of gig venue: "); + String venueName = InputHandler.handleStringInput(sc); + + System.out.print("Enter city/state of venue: "); + String city = InputHandler.handleStringInput(sc); + + System.out.print("Enter venue capacity: "); + int capacity = InputHandler.handleIntegerInput(sc); + + Venue venue = new Venue(venueName, city, capacity); + + System.out.print("Enter date of gig: "); + String date = InputHandler.handleStringInput(sc); + + System.out.print("How much is the gig paying? "); + double payment = InputHandler.handleDoubleInput(sc); + + Gig newGig = new Gig(date, venue, payment); + bgm.addGig(newGig); + + System.out.println("Gig added successfully."); + } + + //unused in current implementation, can display info about a venue + private void viewVenueInformation() { + if (bgm.getGigs().isEmpty()) { + System.out.println("No gigs available."); + return; + } + + int gigIndex = promptForGigIndex("Enter gig number to view venue information: "); + if (gigIndex == -1) { + return; + } + + Gig gig = bgm.findGigByIndex(gigIndex); + System.out.println(gig.getVenue()); + } + + //calls helper to figure out which gig is being referenced and marks it as complete + private void markGigComplete() { + if (bgm.getGigs().isEmpty()) { + System.out.println("No gigs available."); + return; + } + + int gigIndex = promptForGigIndex("Enter gig number to mark as completed: "); + if (gigIndex == -1) { + return; + } + + boolean success = bgm.markGigCompleteByIndex(gigIndex); + + if (success) { + System.out.println("Gig marked as completed."); + } else { + System.out.println("Invalid gig selection."); + } + } + + //collects user input for which song to use as an argument for bgm.addSongToCatalog + private void addSongToCatalog() { + System.out.print("Enter name of song to add to catalog: "); + String song = InputHandler.handleStringInput(sc); + bgm.addSongToCatalog(song); + System.out.println("Song added to catalog."); + } + + //loops through each song in bgm and prints them + private void viewSongCatalog() { + if (bgm.getSongCatalog().isEmpty()) { + System.out.println("Song catalog is empty."); + return; + } + + System.out.println("Song Catalog:"); + for (int i = 0; i < bgm.getSongCatalog().size(); i++) { + System.out.println((i + 1) + ". " + bgm.getSongCatalog().get(i)); + } + } + + //collects user input on which gig to generate a setlist for, generates setlist using bgm method + // based on user input for set length, as well as songs in catalog + private void generateSetlist() { + if (bgm.getGigs().isEmpty()) { + System.out.println("No gigs available."); + return; + } + + if (bgm.getSongCatalog().isEmpty()) { + System.out.println("Song catalog is empty."); + return; + } + + System.out.println("Select a gig to generate a setlist for:"); + bgm.viewAllGigs(); + + int gigIndex = promptForGigIndex("Enter gig number: "); + if (gigIndex == -1) { + return; + } + + System.out.print("How many songs should be in the setlist? "); + int numberOfSongs = InputHandler.handleIntegerInput(sc); + + boolean success = bgm.generateSetlistForGigByIndex(gigIndex, numberOfSongs); + + if (!success) { + System.out.println("Could not generate setlist. The gig may be invalid or already completed."); + return; + } + + Gig gig = bgm.findGigByIndex(gigIndex); + System.out.println("Setlist generated for this gig."); + System.out.println("Setlist: " + gig.getSetlist()); + } + + //takes user input to use for displaying setlist info about a particular gig + private void viewGigSetlist() { + if (bgm.getGigs().isEmpty()) { + System.out.println("No gigs available."); + return; + } + + System.out.println("Select a gig to view its setlist:"); + bgm.viewAllGigs(); + + int gigIndex = promptForGigIndex("Enter gig number: "); + if (gigIndex == -1) { + return; + } + + + + Gig gig = bgm.findGigByIndex(gigIndex); + + if (gig.getSetlist().isEmpty()) { + System.out.println("This gig does not have a setlist yet."); + return; + } + + System.out.println("\nSetlist for " + gig.getDate() + " at " + gig.getVenue().getName() + ":"); + for (int i = 0; i < gig.getSetlist().size(); i++) { + System.out.println((i + 1) + ". " + gig.getSetlist().get(i)); + } + } + + //takes user input to use for displaying info about a particular gig + private void viewGigDetails() { + if (bgm.getGigs().isEmpty()) { + System.out.println("No gigs available."); + return; + } + + System.out.println("Select a gig to view details:"); + bgm.viewAllGigs(); + + int gigIndex = promptForGigIndex("Enter gig number: "); + if (gigIndex == -1) { + return; + } + + bgm.viewGigDetails(gigIndex); + } + + //takes user input to use in bgm method to manually add a song to a setlist + private void addSongToGigSetlist() { + if (bgm.getGigs().isEmpty()) { + System.out.println("No gigs available."); + return; + } + + System.out.println("Select a gig to add a song to:"); + bgm.viewAllGigs(); + + int gigIndex = promptForGigIndex("Enter gig number: "); + if (gigIndex == -1) { + return; + } + + System.out.print("Enter song name to add to this gig's setlist: "); + String song = InputHandler.handleStringInput(sc); + + boolean success = bgm.addSongToGigSetlist(gigIndex, song); + + if (success) { + System.out.println("Song added to this gig's setlist."); + } else { + System.out.println("Cannot modify the setlist of a completed or invalid gig."); + } + } + + //takes user input to use in bgm method to manually remove a song from a setlist + private void removeSongFromGigSetlist() { + if (bgm.getGigs().isEmpty()) { + System.out.println("No gigs available."); + return; + } + + System.out.println("Select a gig to remove a song from:"); + bgm.viewAllGigs(); + + int gigIndex = promptForGigIndex("Enter gig number: "); + if (gigIndex == -1) { + return; + } + + Gig gig = bgm.findGigByIndex(gigIndex); + + if (gig.getSetlist().isEmpty()) { + System.out.println("This gig does not have a setlist yet."); + return; + } + + System.out.println("Current setlist:"); + for (int i = 0; i < gig.getSetlist().size(); i++) { + System.out.println((i + 1) + ". " + gig.getSetlist().get(i)); + } + + System.out.print("Enter the number of the song to remove: "); + int songIndex = InputHandler.handleIntegerInput(sc); + + String removedSong = bgm.removeSongFromGigSetlist(gigIndex, songIndex - 1); + + if (removedSong == null) { + System.out.println("Could not remove song. The gig may be completed or the selection was invalid."); + } else { + System.out.println("Removed song: " + removedSong); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Venue.java b/src/main/java/org/codedifferently/Venue.java new file mode 100644 index 0000000..1776f4f --- /dev/null +++ b/src/main/java/org/codedifferently/Venue.java @@ -0,0 +1,46 @@ +package org.codedifferently; + +public class Venue { + private String name; + private String city; + private int capacity; + + public Venue() { + } + + public Venue(String name, String city, int capacity) { + this.name = name; + this.city = city; + this.capacity = capacity; + } + + //getters and setters + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public int getCapacity() { + return capacity; + } + + public void setCapacity(int capacity) { + this.capacity = capacity; + } + + @Override + public String toString() { + return name + " - " + city + " | Capacity: " + capacity; + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/helpers/InputHandler.java b/src/main/java/org/codedifferently/helpers/InputHandler.java new file mode 100644 index 0000000..b320d06 --- /dev/null +++ b/src/main/java/org/codedifferently/helpers/InputHandler.java @@ -0,0 +1,38 @@ +package org.codedifferently.helpers; + +import java.util.Scanner; + +public class InputHandler { + + public static int handleIntegerInput(Scanner scan) { + while (true) { + try { + int input = Integer.parseInt(scan.nextLine()); + return input; + } catch (NumberFormatException e) { + System.out.println("Invalid input! Please enter a whole number."); + } + } + } + + public static double handleDoubleInput(Scanner scan) { + while (true) { + try { + double input = Double.parseDouble(scan.nextLine()); + return input; + } catch (NumberFormatException e) { + System.out.println("Invalid input! Please enter a valid number."); + } + } + } + + public static String handleStringInput(Scanner scan) { + while (true) { + String input = scan.nextLine().trim(); + if (!input.isEmpty()) { + return input; + } + System.out.println("Invalid input! Please enter a non-empty value."); + } + } +} \ No newline at end of file