Hi, Im pretty new to java, and this is my first time using Arraylist. Im having trouble having storing the users input to the arraylist, i know i have to use add. .. but its not working. Any help would be thank full. Ill post my appointment class, and my other class that im using to get the users input.
//This is my appointment class, basicly has date, time, and owners name of a appointment.
public class Appointment implements Comparable<Appointment> { private String date; private String time; Owner owner; public Appointment(String date, String time, Owner owner) { this.date = date; this.time = time; this.owner = owner; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public String getTime() { return time; } public void setTime(String time) { this.time = time; } public Owner getOwner() { return owner; } public void setOwner(Owner owner) { this.owner = owner; } public String toString() { return "(Owner name: " + owner.getName() + ", Date: " + date + ", Time: " + time + ")"; } // return number < 0 if THIS appointment comes before 'a'. Returns > 0 if comes AFTER. 0 if same date public int compareTo(Appointment a) { return getDate().compareTo(a.getDate()); } }
// This class basicly is the main menu, and it should get the users input and store it in the appointment arraylist.
//this class isnt done, but if i can get case 5 to work i should be fine with the rest of the cases.
import java.util.ArrayList; import java.util.Scanner; /** * @author Sarmen * */ public class Menu { public static int MenuSelection() { Scanner kb = new Scanner(System.in); int selection = 0; ArrayList<Appointment> appts = new ArrayList<Appointment>(); ArrayList<Animal> animals = new ArrayList<Animal>(); ClientDataBase db = new ClientDataBase(appts, animals); while (true) { System.out.println("Welcome to Sarmen's Veterinarian office"); System.out.println("What would you like to do? "); System.out.println("[1]. See all appointments"); System.out.println("[2]. Search by Date"); System.out.println("[3]. Search by Owner"); System.out.println("[4]. Search by Animal(Dog/Fish/Bird)"); System.out.println("[5]. Add appointment"); System.out.println("[6]. Exit"); selection = kb.nextInt(); switch (selection) { case 1: System.out.println("All appointments"); db.printAllAppointments(); break; case 2: System.out.println("Date of appointment to search: "); break; case 3: System.out.println("Owners name to search: "); break; case 4: System.out.println("Enter(Dog/Fish/Bird): "); break; case 5: System.out.println("Adding Appointment"); kb.nextLine(); System.out.println("Enter Date(mm/dd/yy): "); appts.add(new Appointment(null ,null, null)); //i think im not supposed to have all the nulls kb.nextLine(); System.out.println("Enter time(hh:mm am/pm)"); appts.add(null); kb.nextLine(); System.out.println("Enter Owner name)"); appts.add(null); kb.nextLine(); db.printAllAppointments(); break; case 6: System.out.println("Exit"); System.exit(0); default: System.out.println("Please enter a valid selection."); } return selection; } } }