Create a constructor for the Delivery class that accepts arguments for the year, month, and delivery number within the month, delivery distance code, and weight of the package. The constructor determines the six-digit delivery number and delivery fee. Also include a method that displays every Delivery object field. Save the file as Delivery.java.

import javax.swing.*;
import java.util.*;
class Delivery                 
{                                     
 	private String deliveryNumber;
	double fee;
	
 	
	public Delivery(int year, int month, int deliveryNo, int distance, double weight)
		{
		 	int digit1, digit2, digit3, digit4, digit5, digit6 ;	
			if (distance == 1)
				if(weight < 5)
					fee = 12.00;
				else
				 if(weight > 20)
				 	fee = 22.00;
				else
				 if(weight >= 5 && weight <= 20)
				 	fee = 16.50;
			else // ..."if the distance is NOT == 1, but == 2"...[goes with line 14]
				if(weight < 5)
					fee = 35.00;
				else
					fee = 47.95;
   

			digit1 = year - 2000; 				 
			if(month < 10)
			{
				digit2 = 0;
				digit3 = month;
			}
			else //...for months 10, 11 and 12...
			{
				digit2 = month / 10;
				digit3 = month % 10;
			}
			
			if (deliveryNo < 10) //...for the month's deliveries number 1 thru 9...
			{
				digit4 = 0;
				digit5 = 0;
				digit6 = deliveryNo;
			}
 			
			else
				if (deliveryNo < 100) //...for the month's deliveries number 10 thru 99...
				{
					digit4 = 0;
					digit5 = deliveryNo / 10;
					digit6 = deliveryNo % 10;
				}
				else              //... for the remaining deliveries (#'s 100 thru 999)...
				{
					digit4 = deliveryNo / 100;                    //...captures the hundreds column digit...
					digit5 = (deliveryNo - (digit4 * 100)) / 10;  //...removes hundreds column digit, then captures the tens column digit...
					digit6 = deliveryNo % 10;
				}
			deliveryNumber = "" + digit1 + digit2 + digit3 +
				digit4 + digit5 + digit6;
		}
}
import java.util.Scanner;

public class CreateDelivery
{
   public static void main(String []args)
   {
      Scanner input=new Scanner(System.in);
	  
      System.out.print("Enter year: ");
      int y=input.nextInt();
	  
      while((y<2001)||(y>2009))
	  {
         System.out.println("Year should be in the range of (2001 - 2009).");
         System.out.print("Please re-enter year: ");
         y=input.nextInt();
      }
	  
	  System.out.print("Enter month: ");
      int mon=input.nextInt();
	  
      while((mon<1)||(mon>12))
	  {
         System.out.println("Month should be in the range of (1 - 12).");
         System.out.print("Please re-enter month: ");
         mon=input.nextInt();
      }
	  
      System.out.print("Enter delivery no: ");
      int no=input.nextInt();
	  
      while((no<1)||(no>1000))
	  {
         System.out.println("Delivery No should be in the range of (1 - 999).");
         System.out.print("Please re-enter delivery no: ");
         no=input.nextInt();
      }
	  
      System.out.print("Enter weight: ");
      double w=input.nextDouble();
	  
      while((w<0.1)||(w>101))
	  {
         System.out.println("Weight should be in the range of (0.1 lb - 100 lbs).");
         System.out.print("Please re-enter weight: ");
         w=input.nextDouble();
      }
	  
      System.out.print("Enter delivery code: ");
      int code=input.nextInt();
	  
      while((code<1)||(code>2))
	  {
         System.out.println("Code No should be either 1 or 2.");
         System.out.print("Please re-enter code: ");
         code=input.nextInt();
      }
      Delivery delivery = new Delivery(y,mon,no,w,code);
      double fees=delivery.displayFees(code,w);
      System.out.println(code+" "+deliveryNumber+" "+w+" "+fees);
   }
}

in the compilier it isn't liking the new in "Delivery delivery = new Delivery(y,mon,no,w,code);" and the deliveryNumber in "System.out.println(code+" "+deliveryNumber+" "+w+" "+fees);"

Recommended Answers

All 2 Replies

First, your constructor is expecting 4 ints and a double, but you're passing 3 ints, a double and an int to the Delivery class, in your CreateDelivery class.

Also, the Delivery class has no such method as "displayFees()", and the variable "deliveryNumber" on line 62 of CreateDelivery is not defined anywhere.

First, your constructor is expecting 4 ints and a double, but you're passing 3 ints, a double and an int to the Delivery class, in your CreateDelivery class.

Also, the Delivery class has no such method as "displayFees()", and the variable "deliveryNumber" on line 62 of CreateDelivery is not defined anywhere.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.