3072>
Hvis vi tager kodne fra
http://www.eksperten.dk/spm/362201, så
ser den da ud til at virke for maxiletter også:
/**
* Letter information what kind of letter are we dealing with defined by length,
* width, thickness and weight.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Category {
// instance variables
private int length, width, weight;
private double thickness;
private String country;
/**
* Constructor for objects of class Category
*/
public Category(int l, int w, int we, double t, String c) {
// initialise instance variables
length = l;
width = w;
weight = we;
thickness = t;
country = c;
}
//*Find out which type of letter we are dealing with according to weight,width, length and thicknes.*/
public String getType() {
if ((length <= 23)
&& (width <= 17)
&& (weight <= 50)
&& (thickness <= 0.5)) {
return "Standardletter";
} else if (
(length <= 33)
&& (width <= 23)
&& (weight <= 1000)
&& (thickness <= 2)) {
return "Largeletter";
} else if (
(length <= 60)
&& (length + width + thickness <= 90)
&& (weight <= 2000)) {
return "Maxiletter";
} else {
return "Not a letter";
}
}
//* Then we have to make the postage calculation according to weight and country.*/
public double calculatePostage() {
if ((getType().equals("Standardletter"))
&& (weight <= 50)
&& country.equals("Denmark")) {
return 4.25;
}
if ((getType().equals("Standardletter"))
&& (weight <= 50)
&& country.equals("Europ, The Faroes Island and Greenland")) {
return 5.50;
}
if ((getType().equals("Standardletter"))
&& (weight <= 50)
&& country.equals("Other foreign countries")) {
return 6.50;
}
if ((getType().equals("Largeletter"))
&& (weight <= 50)
&& country.equals("Denmark")) {
return 5.50;
}
if ((getType().equals("Largeletter"))
&& (weight <= 100)
&& country.equals("Denmark")) {
return 6.50;
}
if ((getType().equals("Largeletter"))
&& (weight <= 250)
&& country.equals("Denmark")) {
return 12.00;
}
if ((getType().equals("Largeletter"))
&& (weight <= 500)
&& country.equals("Denmark")) {
return 20.00;
}
if ((getType().equals("Largeletter"))
&& (weight <= 1000)
&& country.equals("Denmark")) {
return 28.00;
}
if ((getType().equals("Largeletter"))
&& (weight <= 50)
&& country.equals("Europe, The Faroes Island and Greenland")) {
return 8.50;
}
if ((getType().equals("Largeletter"))
&& (weight <= 100)
&& country.equals("Europe, The Faroes Island and Greenland")) {
return 12.00;
}
if ((getType().equals("Largeletter"))
&& (weight <= 250)
&& country.equals("Europe, The Faroes Island and Greenland")) {
return 19.00;
}
if ((getType().equals("Largeletter"))
&& (weight <= 500)
&& country.equals("Europe, The Faroes Island and Greenland")) {
return 33.00;
}
if ((getType().equals("Largeletter"))
&& (weight <= 1000)
&& country.equals("Europe, The Faroes Island and Greenland")) {
return 57.00;
}
if ((getType().equals("Largeletter"))
&& (weight <= 50)
&& country.equals("Other foreign countries")) {
return 11.50;
}
if ((getType().equals("Largeletter"))
&& (weight <= 100)
&& country.equals("Other foreign countries")) {
return 18.00;
}
if ((getType().equals("Largeletter"))
&& (weight <= 250)
&& country.equals("Other foreign countries")) {
return 33.00;
}
if ((getType().equals("Largeletter"))
&& (weight <= 500)
&& country.equals("Other foreign countries")) {
return 56.00;
}
if ((getType().equals("Largeletter"))
&& (weight <= 1000)
&& country.equals("Other foreign countries")) {
return 95.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 50)
&& country.equals("Denmark")) {
return 7.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 100)
&& country.equals("Denmark")) {
return 9.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 250)
&& country.equals("Denmark")) {
return 15.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 500)
&& country.equals("Denmark")) {
return 24.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 1000)
&& country.equals("Denmark")) {
return 32.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 2000)
&& country.equals("Denmark")) {
return 40.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 50)
&& country.equals("Europe, The Faroes Island and Greenland")) {
return 14.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 100)
&& country.equals("Europe, The Faroes Island and Greenland")) {
return 19.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 250)
&& country.equals("Europe, The Faroes Island and Greenland")) {
return 26.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 500)
&& country.equals("Europe, The Faroes Island and Greenland")) {
return 41.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 1000)
&& country.equals("Europe, The Faroes Island and Greenland")) {
return 65.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 2000)
&& country.equals("Europe, The Faroes Island and Greenland")) {
return 100.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 50)
&& country.equals("Other foreign countries")) {
return 19.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 100)
&& country.equals("Other foreign countries")) {
return 27.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 250)
&& country.equals("Other foreign countries")) {
return 41.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 500)
&& country.equals("Other foreign countries")) {
return 61.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 1000)
&& country.equals("Other foreign countries")) {
return 105.00;
}
if ((getType().equals("Maxiletter"))
&& (weight <= 2000)
&& country.equals("Other foreign countries")) {
return 175.00;
} else {
return -1.0;
}
}
public static void main(String[] args) {
Category brev = new Category(25,10,200,1,"Denmark");
System.out.println(brev.calculatePostage());
Category brev2 = new Category(55,10,200,1,"Denmark");
System.out.println(brev2.calculatePostage());
}
}