Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Schedule {
- int app = 20;
- private Delivery [] arr = new Delivery [app];
- Schedule(){
- arr[0] = new Delivery("Mar", 4, 17, 30, "Pizza");
- arr[1] = new Delivery("Apr", 1, 06, 30, "Special Delivery");
- arr[2] = new Delivery("May", 6, 12, 00, "Amazon (Books)");
- arr[3] = new Delivery("Jun", 3, 11, 15, "Car Parts");
- }//constructor the places the 4 default Delivery objects in the array
- public void run() {
- char in;
- do {
- System.out.println("A)dd Delivery , D)elete Delivery , L)ist Delivery , E)xit");
- System.out.print("Enter your option: ");
- in = UserInput.getChar('A','Z');
- //if (in == 'A' || in == 'a')
- //if (in == 'D' || in == 'd')
- if (in == 'L' || in == 'l')
- this.listDelivery();
- if (in == 'E' || in == 'e')
- System.exit(0);
- }//end do loop
- while (in != 'E' || in != 'e');
- } //end run() method
- public void listDelivery(){
- for(int i = 0, j = 1; i < this.arr.length; i++, j++) {
- if (this.arr[i] != null ) {
- System.out.print(j + ")");
- System.out.println((this.arr[i].toString()));
- }
- }
- }//end listDelivery
- public static void main(String[] args) {
- Schedule sc = new Schedule();
- sc.run();
- }
- }//end class Schedule
- import java.util.Arrays;
- public class Delivery {
- public String month;
- public int day;
- public int hour;
- public int minute;
- public String message;
- public Delivery(String mon, int dy, int hr, int min, String mess){
- setMonth(mon);
- setDay(dy);
- setHour(hr);
- setMin(min);
- setMess(mess);
- } //end constructor with parameters
- public Delivery() {} //contructor with no parameter
- /*
- All the Get methods */
- public String getMonth(){
- return month;
- }
- public int getDay() {
- return day;
- }
- public int getHour(){
- return hour;
- }
- public int getMin(){
- return minute;
- }
- public String getMess(){
- return message;
- }
- /*End of all the get methods */
- /*All the Set methods */
- public void setMonth(String mon){
- this.month = mon;
- }
- public void setDay(int dy){
- this.day = dy;
- }
- public void setHour(int hr){
- this.hour = hr;
- }
- public void setMin(int min){
- this.minute = min;
- }
- public void setMess(String mess){
- this.message = mess;
- }
- /*End of all the set methods */
- @Override
- public String toString(){
- String s = "";
- if (minute > 10){
- s = " " + month + " " + day + ", " + hour + ":" + minute +" " + message;
- }
- else if(minute < 9){
- System.out.printf(" " + month + " " + day + ", "+ hour + ":%02d",minute);
- System.out.print(" " + message);
- }
- return s;
- }
- public static Delivery inputDelivery() {
- Delivery del = new Delivery();
- UserInput input = new UserInput();
- String month[] = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug",
- "sep", "oct", "nov", "dec"};
- do {
- System.out.print("Enter the month: ");
- String str = input.getString(1,3);
- del.setMonth(str.substring(0,1).toUpperCase() + str.substring(1).toLowerCase());
- } while(!Arrays.asList(month).contains(del.month.toString().toLowerCase()));
- System.out.print("Enter the day: ");
- del.setDay(input.getInt(1,31));
- System.out.print("Enter the hour: ");
- del.setHour(input.getInt(0,23));
- System.out.print("Enter the minute(s): ");
- del.setMin(input.getInt(0,59));
- System.out.print("Enter the message: ");
- del.setMess(input.getString(1,40));
- return del;
- }//end inputDelivery()
- public static void main(String[] args) {
- Delivery NewDel = inputDelivery();
- System.out.println(NewDel);
- }//end main()
- }
Add Comment
Please, Sign In to add comment