title: Java - Calling methods from other classes with calculated fields
body: <p>So I've been looking at this piece of code all afternoon and I can't see the error(s). Here is what I'm supposed to do:</p>
  
  <p>Create a <code>Delivery</code> class for a delivery service. The class contains fields to hold the following: </p>
  
  <ul>
  <li>A delivery number that contains eight digits. The first four digits represent the year, and the last four digits represent the delivery number. </li>
  <li>A code representing the delivery area. A local delivery is code 1, and a long distance delivery is code 2.</li>
  <li>A weight, in pounds, of the item to be delivered.</li>
  <li>The fee for the delivery, as follows:</li>
  </ul>
  
  <p>Create a constructor for the <code>Delivery</code> class that accepts arguments for the year,
  delivery number within the year, delivery distance code, and weight of the package. The
  constructor determines the eight-digit delivery number and delivery fee. Also include a
  method that displays every <code>Delivery</code> object field. Save the file as Delivery.java.</p>
  
  <p>Next, create an application that prompts the user for data for a delivery. Keep
  prompting the user for each of the following values until they are valid:</p>
  
  <ul>
  <li>A four-digit year between 2001 and 2025 inclusive</li>
  <li>A delivery number for the year between 1 and 9999 inclusive</li>
  <li>A package weight between 0.10 pound and 100 pounds inclusive</li>
  <li>A delivery distance code that is either 1 or 2</li>
  </ul>
  
  <p>When all the data entries are valid, construct a <code>Delivery</code> object, and then display its
  values. Save the file as <code>CreateDelivery.java</code>.</p>
  
  <p>So here is my delivery Class</p>
  
  <pre><code>import javax.swing.*;
  import java.util.*;
  
  
  class Delivery 
  {
      //variables
      private int year;
      private int deliveryNumber; //deliveryNo
      private double weight;
      private int distanceCode; //code
  
          //constructor
          //Delivery()
          //{
          //  year = year;
          //  deliveryNumber = deliveryNumber;
          //  weight = weight;
          //  distanceCode = distanceCode;
          //}
  
      //get year
      public int getYear()
      {
          return year;
      }
      //set year
      public int setYear (int newYear)
      {
          year = newYear;
          return year;
      }
  
      //get deliveryNumber
      public int getDeliveryNumber()
      {
          return deliveryNumber;
      }
      //set deliveryNumber
      public int setDeliveryNumber (int newDeliveryNumber)
      {
          deliveryNumber = newDeliveryNumber;
          return deliveryNumber;
      }
  
      //get weight
      public double getWeight()
      {
          return weight;
      }
      //set Weight
      public double setWeight (double newWeight)
      {
          weight = newWeight;
          return weight;
      }   
  
  
      //get distanceCode
      public int getDistanceCode()
      {
          return distanceCode;
      }
      //set distanceCode
      public int setDistanceCode (int newDistanceCode)
      {
          distanceCode = newDistanceCode;
          return distanceCode;
      }   
  
      //calculate fee
      public double displayFees(int distance, double w) //distance = c
      {
          double fees = 0;
  
      if(distance == 1)
      {
              if(w &lt; 5)
          {
              fees = 12;
          }
          else if((w &lt; 20)&amp;&amp;(w &gt; 5))
          {
              fees = 16.50;
          }
          else if(w &gt; 20)
          {
              fees = 22;
          }
      }
      else if(distance == 2)
      {
          if(w &lt; 5)
          {
              fees = 35;
          }
          else if(w &gt;= 5)
          {
              fees = 47.95;
          }
      }
          return fees;
      }
  
      //display method
      public void display(int year, int deliveryNumber, double weight, int distanceCode)
          {
          System.out.println("Year: " + year + '\n' 
              + "Delivery Number: " + deliveryNumber + '\n' 
              + "Weight of the package: " + weight + '\n'
              + "Delivery code: " + distanceCode);
          }
  }
  </code></pre>
  
  <p>And here is my CreateDelivery Class</p>
  
  <pre><code> import javax.swing.JOptionPane;
  import java.util.Scanner;
  
  public class CreateDelivery
      {
          public static void main(String []args)
  
          {
  
              Delivery delivery1 = new Delivery();
  
              //scanner year
              Scanner input = new Scanner(System.in);
              System.out.print("Please enter the current year, format (yyyy) &gt;&gt;&gt; ");
              delivery1.setYear(input.nextInt());
  
              //loop year
                      while((delivery1.getYear() &lt;= 2000)||(delivery1.getYear() &gt;= 2026))
                      {
                          System.out.println('\n'+ "Error, year should be in the range of (2010 - 2025). Please enter a valid option &gt;&gt; ");
                          delivery1.setYear(input.nextInt());
                      }
  
              //scanner for delivery number
              System.out.print('\n'+ "Please enter a delivery number: ");
              delivery1.setDeliveryNumber(input.nextInt());
  
              //loop for delivery number
                      while((delivery1.getDeliveryNumber() &lt;= 0001)||(delivery1.getDeliveryNumber() &gt;= 10000))
                      {
                          System.out.println("Error, the delivery number is a 4 digit number between 0001 and 9999, please enter a valid option &gt;&gt; ");
                          delivery1.setDeliveryNumber(input.nextInt());
                      }
  
              //scanner for weight
              System.out.print("Please enter the weight of the package (in pounds): ");
              delivery1.setWeight(input.nextDouble());
  
                      //loop for weight
                      while((delivery1.getWeight() &lt;= .09)||(delivery1.getWeight() &gt;= 101))
                      {
                          System.out.println("Error, the minimum allowed weight is 0.10 pounds and the maximum is 100 pounds. Please enter a valid weight &gt;&gt; ");
                          delivery1.setWeight(input.nextDouble());
                      }
  
              //scanner for delivery code
              System.out.print("Please enter 1 for local or 2 for long distance deliveries &gt;&gt; ");
              delivery1.setDistanceCode(input.nextInt());
  
                      //loop for delivery code
                      while((delivery1.getDistanceCode() == 1) &amp;&amp; (delivery1.getDistanceCode() == 2))
                      {
                          System.out.println("Error, please enter a valid distance code (1 for local deliveries and 2 for long distance deliveries) &gt;&gt; ");
                          delivery1.setDistanceCode(input.nextInt());
                      }
  
              //turn int to string
              String n = Integer.toString(delivery1.getDeliveryNumber());
              String y = Integer.toString(delivery1.getYear());
  
              String trackingNumber = n + y;
              System.out.println(delivery1.getDistanceCode() + " " 
              + trackingNumber + " " + delivery1.getWeight() + " " + fees);
  
      }
  
  }
  </code></pre>
  
  <p>So I made the changes you guys suggested, but now I can't pull fees from the Delivery class. Any thoughts?</p>