Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone please help me with this JAVA code! See the \"Pack\" and \"Date\" cl

ID: 3836723 • Letter: C

Question

Can someone please help me with this JAVA code!

See the "Pack" and "Date" classes. You must write the "SpecialPack" class for a Package Delivery System. A package consists of a unique, system created package ID (numeric), delivery zone (char and int pair, i.e A1 though Z9, see below for grid), the delivery date of the package (see Date class), and the package’s weight and volume (positive integers).  Packages are regular delivery (any time). SpecialPackages have a specific delivery deadline (delivered by a specific military hour 916). Use must create the "SpecialPack" subclass and include the following

a. Necessary constants

b. Instance variable as described above

c. Nondefault constructor

d. Standard accessor/mutator Methods – for the instance variable, with basic data range validation as denoted above

e. toString Method Delivery Zone Grid, rows A through Z, columns 1 through 9

A1 A2 A3 A4 A5 A6 A7 A8 A9

B1 B2 B3 B4 B5 B6 B7 B8 B9

C1 C2 C3 C4 C5 C6 C7 C8 C9

. . .   . . .  

X1 X2 X3 X4 X5 X6 X7 X8 X9

Y1 Y2 Y3 Y4 Y5 Y6 Y7 Y8 Y9

Z1 Z2 Z3 Z4 Z5 Z6 Z7 Z8 Z9

these are the Date and Pack classes to use for the problem
public class Date {
private int month, day, year;
public Date( ) { setDate( 1, 1, 2000 ); }
public Date( int mm, int dd, int yyyy ) { setDate( mm, dd, yyyy ); }
public int getMonth( ) { return month; }
public int getDay( ) { return day; }
public int getYear( ) { return year; }
public void setDate( int mm, int dd, int yyyy ) {
setYear(yyyy); setMonth( mm ); setDay( dd );
}
private void setMonth( int mm ) { month = ( mm >= 1 && mm <= 12 ? mm : 1 ); }
private void setDay( int dd ) {
int [] validDays = {0,31,29,31,30,31,30,31,31,30,31,30,31};
if (!leapYear()) validDays[2]=28;
day = ( dd >= 1 && dd <= validDays[month] ? dd : 1 );
}
private void setYear( int yyyy ) { year = yyyy; }
public boolean leapYear() {
if (!((year%4==0) && ((year%100!=0)||(year%400==0)))) return false;
else return true;
}
public String toString( ) { return month + "/" + day + "/" + year; }
}
public class Pack {
private static int counter=1;
private static final int DEFAULT_WEIGHT=5;
private static final int DEFAULT_VOLUME=36;
private static final String DEFAULT_ZONE="A1";
private int packageID; private String zone;
private Date deliveryDate; int weight, volume;
public Pack(String newZone, Date newDate, int newWeight, int newVolume) {
packageID=counter; setZone(newZone); setDeliveryDate(newDate);
setWeight(newWeight); setVolume(newVolume); counter++;
}
public int getPackageID(){return packageID;}
public String getZone(){return zone;}
public void setZone(String newZone){
if (newZone.charAt(0)>='A' && newZone.charAt(0)<='Z'&&
newZone.charAt(1)>='1' && newZone.charAt(1)<='9')
zone=newZone;
else zone = DEFAULT_ZONE;
}
public Date getDeliveryDate() {
return new Date(deliveryDate.getMonth(),deliveryDate.getDay(),deliveryDate.getYear());
}
public void setDeliveryDate(Date newDate) {
deliveryDate=new Date(newDate.getMonth(),newDate.getDay(),newDate.getYear());
}
public int getWeight(){return weight;}
public void setWeight(int newWeight) {
if (newWeight>0) weight=newWeight;
else weight= DEFAULT_WEIGHT;
}
public int getVolume(){return volume;}
public void setVolume(int newVolume) {
if (newVolume>0) volume=newVolume;
else volume= DEFAULT_VOLUME;
}
public String toString() {
return packageID+" "+zone+" " +deliveryDate+" "+weight+" "+volume;
}
}

Explanation / Answer

code:

package chegg;

public class datedemo {
   public static void main(String args[]){
       Pack p1=new Pack("A3",new Date(5,12,2017),100,100);
       System.out.println(p1);
       SpecialPack sp1=new SpecialPack("C2",new Date(6,7,2017),200,150,new Date(6,8,2017));
       System.out.println(sp1);
       SpecialPack sp2=new SpecialPack("Z6",new Date(7,29,2017),600,70,new Date(6,8,2017));
       System.out.println(sp2);
   }
}
class Date {
private int month, day, year;
public Date( ) { setDate( 1, 1, 2000 ); }
public Date( int mm, int dd, int yyyy ) { setDate( mm, dd, yyyy ); }
public int getMonth( ) { return month; }
public int getDay( ) { return day; }
public int getYear( ) { return year; }
public void setDate( int mm, int dd, int yyyy ) {
setYear(yyyy); setMonth( mm ); setDay( dd );
}
private void setMonth( int mm ) { month = ( mm >= 1 && mm <= 12 ? mm : 1 ); }
private void setDay( int dd ) {
int [] validDays = {0,31,29,31,30,31,30,31,31,30,31,30,31};
if (!leapYear()) validDays[2]=28;
day = ( dd >= 1 && dd <= validDays[month] ? dd : 1 );
}
private void setYear( int yyyy ) { year = yyyy; }
public boolean leapYear() {
if (!((year%4==0) && ((year%100!=0)||(year%400==0)))) return false;
else return true;
}
public String toString( ) { return month + "/" + day + "/" + year; }
public int compare(Date date){
   if(this.getYear()<=date.getYear() && this.getMonth()<=date.getMonth() && this.getDay()<=date.getDay())
           return -1;

   return 0;  
}
}
class Pack {
private static int counter=1;
private static final int DEFAULT_WEIGHT=5;
private static final int DEFAULT_VOLUME=36;
private static final String DEFAULT_ZONE="A1";
private int packageID; private String zone;
private Date deliveryDate; int weight, volume;
public Pack(String newZone, Date newDate, int newWeight, int newVolume) {
packageID=counter; setZone(newZone); setDeliveryDate(newDate);
setWeight(newWeight); setVolume(newVolume); counter++;
}
public int getPackageID(){return packageID;}
public String getZone(){return zone;}
public void setZone(String newZone){
if (newZone.charAt(0)>='A' && newZone.charAt(0)<='Z'&&
newZone.charAt(1)>='1' && newZone.charAt(1)<='9')
zone=newZone;
else zone = DEFAULT_ZONE;
}
public Date getDeliveryDate() {
return new Date(deliveryDate.getMonth(),deliveryDate.getDay(),deliveryDate.getYear());
}
public void setDeliveryDate(Date newDate) {
deliveryDate=new Date(newDate.getMonth(),newDate.getDay(),newDate.getYear());
}
public int getWeight(){return weight;}
public void setWeight(int newWeight) {
if (newWeight>0) weight=newWeight;
else weight= DEFAULT_WEIGHT;
}
public int getVolume(){return volume;}
public void setVolume(int newVolume) {
if (newVolume>0) volume=newVolume;
else volume= DEFAULT_VOLUME;
}
public String toString() {
return packageID+" "+zone+" " +deliveryDate+" "+weight+" "+volume;
}

}
class SpecialPack extends Pack{
   Date deadline;
   public SpecialPack(String newZone, Date newDate, int newWeight,
           int newVolume, Date deadline) {
       super(newZone, newDate, newWeight, newVolume);
       this.deadline=deadline;
      
       // TODO Auto-generated constructor stub
   }
   public Date getDeadline() {
       return deadline;
   }
   public void setDeadline(Date deadline) {
       this.deadline = deadline;
   }
   public String toString() {
       String s= getPackageID()+" "+getZone()+" " +getDeliveryDate()+" "+getWeight()+" "+getVolume()+" "+getDeadline()+":";
       if(getDeliveryDate().compare(deadline)!=-1)
           s+=" delivery date exceeds deadline";
       return s;
   }
}


Output:

1 A3 5/12/2017 100 100
2 C2 6/7/2017 200 150 6/8/2017:
3 Z6 7/29/2017 600 70 6/8/2017: delivery date exceeds deadline