Guest User

Untitled

a guest
Jul 21st, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.10 KB | None | 0 0
  1.     public class Schedule {
  2.      
  3.         int app = 20;
  4.         private Delivery [] arr = new Delivery [app];
  5.         Schedule(){
  6.             arr[0] = new Delivery("Mar", 4, 17, 30, "Pizza");
  7.             arr[1] = new Delivery("Apr", 1, 06, 30, "Special Delivery");
  8.             arr[2] = new Delivery("May", 6, 12, 00, "Amazon (Books)");
  9.             arr[3] = new Delivery("Jun", 3, 11, 15, "Car Parts");
  10.         }//constructor the places the 4 default Delivery objects in the array
  11.        
  12.        
  13.         public void run() {
  14.             char in;
  15.            
  16.             do {
  17.                 System.out.println("A)dd Delivery , D)elete Delivery , L)ist Delivery , E)xit");
  18.                 System.out.print("Enter your option: ");
  19.                 in = UserInput.getChar('A','Z');
  20.                
  21.                 //if (in == 'A' || in == 'a')
  22.                    
  23.                 //if (in == 'D' || in == 'd')
  24.                
  25.                 if (in == 'L' || in == 'l')
  26.                     this.listDelivery();
  27.                
  28.                 if (in == 'E' || in == 'e')
  29.                     System.exit(0);
  30.             }//end do loop
  31.             while (in != 'E' || in != 'e');
  32.            
  33.         } //end run() method
  34.        
  35.        
  36.         public void listDelivery(){
  37.             for(int i = 0, j = 1; i < this.arr.length; i++, j++) {
  38.                 if (this.arr[i] != null ) {
  39.                     System.out.print(j + ")");
  40.                      System.out.println((this.arr[i].toString()));
  41.                 }
  42.             }        
  43.         }//end listDelivery
  44.        
  45.          public static void main(String[] args) {
  46.              Schedule sc = new Schedule();
  47.              sc.run();
  48.              
  49.          }
  50.     }//end class Schedule
  51.      
  52.      
  53.      
  54.      
  55.     import java.util.Arrays;
  56.      
  57.     public class Delivery {
  58.            
  59.         public String month;
  60.         public int day;
  61.         public int hour;
  62.         public int minute;
  63.         public String message;
  64.        
  65.         public Delivery(String mon, int dy, int hr, int min, String mess){
  66.             setMonth(mon);
  67.             setDay(dy);
  68.             setHour(hr);
  69.             setMin(min);        
  70.             setMess(mess);
  71.            
  72.         } //end constructor with parameters
  73.        
  74.         public Delivery() {} //contructor with no parameter
  75.        
  76.        
  77.         /*  
  78.          All the Get methods */
  79.        
  80.         public String getMonth(){
  81.             return month;
  82.         }
  83.          
  84.         public int getDay() {
  85.             return day;
  86.         }
  87.        
  88.         public int getHour(){
  89.             return hour;
  90.         }
  91.          
  92.         public int getMin(){
  93.             return minute;
  94.         }
  95.      
  96.         public String getMess(){
  97.             return message;
  98.         }
  99.         /*End of all the get methods   */
  100.      
  101.        
  102.         /*All the Set methods   */
  103.         public void setMonth(String mon){
  104.             this.month = mon;
  105.         }
  106.        
  107.         public void setDay(int dy){
  108.             this.day = dy;
  109.         }
  110.        
  111.         public void setHour(int hr){
  112.             this.hour = hr;
  113.         }
  114.        
  115.         public void setMin(int min){
  116.             this.minute = min;
  117.         }
  118.        
  119.         public void setMess(String mess){
  120.             this.message = mess;
  121.         }
  122.         /*End of all the set methods      */
  123.            
  124.        @Override
  125.          public String toString(){
  126.            String s = "";
  127.            if (minute > 10){
  128.               s = " " + month + " " + day + ", " + hour + ":" + minute +" " + message;
  129.            }    
  130.            else if(minute < 9){
  131.               System.out.printf(" " + month + " " + day + ", "+ hour + ":%02d",minute);
  132.               System.out.print(" " + message);
  133.           }
  134.            return s;
  135.           }
  136.            
  137.        
  138.         public static Delivery inputDelivery() {
  139.             Delivery del = new Delivery();
  140.             UserInput input = new UserInput();
  141.            
  142.             String month[] = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug",
  143.                "sep", "oct", "nov", "dec"};
  144.            
  145.             do {
  146.                 System.out.print("Enter the month: ");
  147.                 String str = input.getString(1,3);
  148.                 del.setMonth(str.substring(0,1).toUpperCase() + str.substring(1).toLowerCase());  
  149.             } while(!Arrays.asList(month).contains(del.month.toString().toLowerCase()));
  150.                 System.out.print("Enter the day: ");
  151.                 del.setDay(input.getInt(1,31));        
  152.                 System.out.print("Enter the hour: ");
  153.                 del.setHour(input.getInt(0,23));          
  154.                 System.out.print("Enter the minute(s): ");
  155.                 del.setMin(input.getInt(0,59));
  156.                 System.out.print("Enter the message: ");
  157.                 del.setMess(input.getString(1,40));
  158.          
  159.           return del;
  160.         }//end inputDelivery()
  161.        
  162.        
  163.         public static void main(String[] args) {
  164.            Delivery NewDel = inputDelivery();
  165.            System.out.println(NewDel);
  166.      
  167.         }//end main()
  168.     }
Add Comment
Please, Sign In to add comment