Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- public class Delivery
- {
- private String id;
- public char destType;
- private double weight;
- private double total;
- private int temp = 0;
- public Delivery()
- {
- id = " ";
- destType = ' ';
- weight = 0.0;
- }
- public Delivery(String i,char d,double w)
- {
- id = i;
- destType = d;
- weight = w;
- }
- public String getId(){return id;}
- public char getDestType(){return destType;}
- public double getWeight(){return weight;}
- public String toString()
- {
- return("IDENTIFICATION NUMBER : "+id+"\nDESTINATION TYPE: "+destType+"\nWEIGHT : "+weight);
- }
- public double calculateFee(Delivery bib)
- {
- if(bib.destType == 'L' || bib.destType == 'l')
- {
- if(bib.weight >= 0 && bib.weight < 5)
- {
- total = weight*5.5;
- }
- else if(bib.weight >= 5 && bib.weight < 16)
- {
- total = weight*5.3;
- }
- else if(bib.weight > 16)
- {
- total = weight*5;
- }
- }
- if(bib.destType == 'X' || bib.destType == 'x')
- {
- if(bib.weight > 0 && bib.weight < 5)
- {
- total = (bib.weight*7.5)+10;
- }
- else if(bib.weight >= 5)
- {
- total = (bib.weight*7)+15;
- }
- }
- return total;
- }
- public static void main(String[] args)
- {
- int number = Integer.parseInt(JOptionPane.showInputDialog("NUMBER OF OBJECT :"));
- int temp = 0;
- double highest = 0.0;
- Delivery[] e = new Delivery[number];
- double total = 0.0;
- for(int i = 0; i < number ;i++)
- {
- char destType;
- String id = JOptionPane.showInputDialog("IDENTIFICATION NUMBER :");
- String dest = JOptionPane.showInputDialog("[L]LOCAL / [X]LONG DISTANCE :");
- double weight = Double.parseDouble(JOptionPane.showInputDialog("WEIGHT OF OBJECT :"));
- destType = dest.charAt(0);
- e[i] = new Delivery(id, destType, weight);
- }
- for(int j = 0; j < number; j++)
- {
- total = e[j].calculateFee(e[j]);
- if(total > highest)
- {
- highest = total;
- temp = j;
- }
- }
- JOptionPane.showMessageDialog(null,"the id number of object with highest fee is : "+e[temp].id);
- for(int k = 0; k < number; k++)
- {
- JOptionPane.showMessageDialog(null,e[k].toString()+"\nTotal : "+e[k].calculateFee(e[k]));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement