Проблемы калькулятора пакетов Java - PullRequest
0 голосов
/ 24 октября 2018

Я пытаюсь создать калькулятор пакетов, который будет сообщать мне стоимость пакета в зависимости от веса, который весит пакет.Программа должна выводить общую стоимость пакета и второй вывод, который сообщает, сколько пакет будет стоить со страховкой.Программа выводит, что страховка всегда составляет $ 2,45 (первый вариант), любая помощь будет принята с благодарностью.

package finalAssignment;

import java.util. *;открытый класс UsePackage {

public static void main (String[] args){


    Scanner input = new Scanner(System.in);
            Package pf = new Package ();
            InsuredPackage ip = new InsuredPackage ();
            String userChoice;
            boolean quit = false;

            do {
              System.out.println("A = Air");
              System.out.println("T = Truck");
              System.out.println("M = Mail");
              System.out.println("Q = Quit");
              System.out.print("Your choice: ");
              userChoice = input.next();

              switch (userChoice) {
              case "A":
                    System.out.println ("You have selected shipping by air");
                    System.out.println ("Please enter the package weight");
                    double weight = input.nextDouble();
                    pf.weight = weight;
                    System.out.println(pf.getAir());
                    System.out.println("Insurance will cost " + ip.calculateCost());

                    break;

              case "T":
                  System.out.println ("You have selected shipping by truck");
                    System.out.print("Please enter the package weight: ");
                    pf.weight = input.nextDouble();
                    System.out.println(pf.getTruck());
                    System.out.println("Insurance will cost " + ip.calculateCost());

                    break;

              case "M":
                   System.out.println ("You have selected shipping by mail");
                    System.out.print("Please enter the package weight: ");
                    pf.weight = input.nextDouble();
                    System.out.println(pf.getMail());
                    System.out.println("Insurance will cost " + ip.calculateCost());

                    break;

              case "Q":
                    quit = true;
                    break;

              default:
                    System.out.println("You have entered an invalid option");
                    break;
              }
              System.out.println();
        } while (!quit);
        System.out.println("Thank you for using this program");
}

}

package finalAssignment;

import java.util. *;Пакет открытого класса {

public double weight;
private double Air;
private double Truck;
private double Mail;
private double cost;

public Package (double cost, double weight, double Air, double Truck, double Mail){
    this.cost = cost;
    this.weight = weight;
    this.Air = Air;
    this.Truck = Truck;
    this.Mail = Mail;
}

public Package(){

}

public void setAir (double Air){

    this.Air = Air;

}

public double getAir(){

     if (weight <= 8) {
         System.out.println("The Shipment of package will cost $2.00");
         cost = 2;
     }
                     else {
                          if ((weight >= 9) && (weight <= 16)) {
             System.out.println("The Shipment of package will cost $3.00");
             cost = 3;
         }
                     else {
                         if (weight >= 17) {
                 System.out.println("The Shipment of package will cost $4.50");
                 cost= 4.50;
             }
                         }
                     }
     return cost;
}

public void setTruck (double Truck){

    this.Truck = Truck;

}

public double getTruck (){

    if (weight <= 8) {
        System.out.println("The Shipment of package will cost $1.50");
        cost = 1.50;
    }
                    else {
                         if ((weight >= 9) && (weight <= 16)) {
            System.out.println("The Shipment of package will cost $2.35");
            cost = 2.35;
        }
                    else {
                        if (weight >= 17) {
                System.out.println("The Shipment of package will cost $3.25");
                cost = 3.25;
            }
                        }
                    }

    return cost;

}

public void setMail (double Mail){

    this.Mail = Mail;

}

public double getMail (){

    if (weight <= 8) {
        System.out.println("The Shipment of package will cost $0.50");
        cost = 0.5;
    }
                    else {
                         if ((weight >= 9) && (weight <= 16)) {
            System.out.println("The Shipment of package will cost $1.50");
            cost = 1.50;
        }
                    else {
                        if (weight >= 17) {
                System.out.println("The Shipment of package will cost $2.15");
                cost = 2.15;
            }
                        }
                    }

    return cost;

}


public double getCost() {
    return cost;
}

public void setCost(double cost) {
this.cost = cost;
}

}

package finalAssignment;

Пакет открытого класса InsuredPackage расширяет пакет {

private double ins;

public InsuredPackage (double cost, double weight, double Air, double Truck, double Mail){
    super (cost, weight, Air, Truck, Mail);
}

public InsuredPackage (){
    super ();
}

public void setIns (double ins){
    this.ins = ins;
}

public double calculateCost(){

    if (getCost() >= 0 && getCost() <= 1.00) {
        return getCost() + 2.45;
    }

    if (getCost() >= 1.01 && getCost() <= 3.00) {
        return getCost() + 3.95;
    }

    if (getCost() >= 3.01) {
        return getCost() + 5.55;
    }

    return ins;


}

}

...