Advertisement
biborn

assignment1java

Jul 28th, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. public class Delivery
  4. {
  5.  private String id;
  6.  public char destType;
  7.  private double weight;
  8.  private double total;
  9.  private int temp = 0;
  10.  
  11.  
  12.  public Delivery()
  13.  {
  14.     id = " ";
  15.     destType = ' ';
  16.     weight = 0.0;
  17.  }
  18.  
  19.  
  20.  public Delivery(String i,char d,double w)
  21.  {
  22.      id = i;
  23.      destType = d;
  24.      weight = w;
  25.  }
  26.  
  27.  public String getId(){return id;}
  28.  public char getDestType(){return destType;}
  29.  public double getWeight(){return weight;}
  30.  
  31.  public String toString()
  32.  {
  33.      return("IDENTIFICATION NUMBER : "+id+"\nDESTINATION TYPE: "+destType+"\nWEIGHT : "+weight);
  34.  }
  35.  
  36.  
  37. public double calculateFee(Delivery bib)
  38. {
  39.    
  40.  if(bib.destType == 'L' || bib.destType == 'l')
  41.  {
  42.        if(bib.weight >= 0 && bib.weight < 5)
  43.        {
  44.             total = weight*5.5;
  45.        }
  46.          
  47.            else if(bib.weight >= 5 && bib.weight < 16)
  48.            {
  49.                 total = weight*5.3;
  50.            }
  51.                 else if(bib.weight > 16)
  52.                 {
  53.                     total = weight*5;
  54.                 }
  55.  }  
  56.    
  57.   if(bib.destType == 'X' || bib.destType == 'x')
  58.   {
  59.      if(bib.weight > 0 && bib.weight < 5)
  60.        {
  61.             total = (bib.weight*7.5)+10;
  62.        }
  63.         else if(bib.weight >= 5)
  64.          {
  65.          total = (bib.weight*7)+15;
  66.          }
  67.   }
  68.    
  69.  return total;
  70. }
  71.  
  72. public static void main(String[] args)
  73. {
  74.     int number = Integer.parseInt(JOptionPane.showInputDialog("NUMBER OF OBJECT :"));
  75.     int temp = 0;
  76.     double highest = 0.0;
  77.    
  78.  Delivery[] e = new Delivery[number];
  79.  
  80.  double total = 0.0;
  81.  
  82.  for(int i = 0; i < number ;i++)
  83.  {
  84.   char destType;
  85.  
  86.   String id = JOptionPane.showInputDialog("IDENTIFICATION NUMBER   :");
  87.   String dest = JOptionPane.showInputDialog("[L]LOCAL / [X]LONG DISTANCE :");
  88.   double weight = Double.parseDouble(JOptionPane.showInputDialog("WEIGHT OF OBJECT  :"));
  89.    
  90.  
  91.  destType = dest.charAt(0);
  92.  
  93.  e[i] = new Delivery(id, destType, weight);
  94.  }
  95.  
  96.  for(int j = 0; j < number; j++)
  97.   {
  98.    total = e[j].calculateFee(e[j]);
  99.  
  100.    if(total > highest)
  101.    {
  102.    highest = total;
  103.    temp = j;
  104.    }
  105.  
  106.   }
  107.   JOptionPane.showMessageDialog(null,"the id number of object with highest fee is : "+e[temp].id);
  108.  
  109.   for(int k = 0; k < number; k++)
  110.   {
  111.    JOptionPane.showMessageDialog(null,e[k].toString()+"\nTotal : "+e[k].calculateFee(e[k]));
  112.   }
  113.  }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement