Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //==============================================================================class Package
- class Package{
- private int weight; //in grams
- private String dest; //destination
- //"magic" country codes/destinations, set as constants
- public static final String CAN = "CAN";
- public static final String USA = "USA";
- public Package(int weight, String dest){
- this.weight = weight;
- this.dest = dest;
- }
- public double cost() {
- return 0.0;
- }
- public int getWeight(){
- return weight;
- }
- public int time() {
- if(getDest().equals(Package.CAN)){
- return 3;
- }
- else if(getDest().equals(Package.USA)){
- return 4;
- }
- else{
- return 6;
- }
- }
- public String getDest(){
- return dest;
- }
- public String toString(){
- return weight + "g," + dest;
- }
- }//End class Package
- //=========================================================================subclass Overnight
- class Overnight extends Package{
- public Overnight(int weight, String dest){
- super(weight,dest);
- }
- public double cost(){
- if(getDest().equals(Package.CAN)){
- return Math.round((3.5*getWeight())*100)/100;
- }
- else{
- return Math.round((5.5*getWeight())*100)/100;
- }
- }
- public int time(){
- return 1;
- }
- public String toString(){
- return "Overnight," + super.toString();
- }
- }//End class Overnight
- //=========================================================================subclass Priority
- class Priority extends Package{
- public Priority(int weight, String dest){
- super(weight,dest);
- }
- public double cost(){
- if(getWeight() <=500){
- return 4.25;
- }
- else if(getWeight() >500 && getWeight() <=1000){
- return 5.75;
- }
- else{
- return 7.00;
- }
- }
- public int time(){
- return super.time();
- }
- public String toString(){
- return "Priority," + super.toString();
- }
- }//End class Priority
- //=========================================================================subclass Economy
- class Economy extends Package{
- private int volume; //volume of package in cm³
- public Economy(int weight, String dest, int volume){
- super(weight,dest);
- this.volume = volume;
- }
- public double cost(){
- if(volume <=10000){
- return 2.50;
- }
- else{
- return 3.25;
- }
- }
- public int time(){
- return super.time() * 3;
- }
- public String toString(){
- return "Economy," + super.toString() + "," + volume + "cm³";
- }
- }//End class Priority
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement