/** A Envelope class to handle Envelope only * * @author Freeman Lo * @version 0.0.1 Build 1 Jan 28, 2014. */ import java.io.*; import java.util.*; import java.lang.*; class Envelope { private double weight; private double price; public Envelope() { this.weight = 0.00; this.price = 0.00; } public void askWeight() { Scanner scan = new Scanner(System.in); String mess; System.out.print("Please enter in the weight of the item ? "); mess = scan.nextLine(); mess = mess.trim(); try { this.weight = Double.parseDouble(mess); } catch ( NumberFormatException err) { System.out.println("Wrong Value, Please try again! \n" + err); System.exit(0); } } public double getWeight() { return this.weight; } public void findPrice() { if ( this.weight <= 1 ) { this.price = .98; } else if ( this.weight <= 2 ) { this.price = 1.19; } else if ( this.weight <= 3 ) { this.price = 1.40; } else if ( this.weight <= 4 ) { this.price = 1.61; } else if ( this.weight <= 5 ) { this.price = 1.82; } else if ( this.weight <= 6 ) { this.price = 2.03; } else if ( this.weight <= 7 ) { this.price = 2.24; } else if ( this.weight <= 8 ) { this.price = 2.45; } else if ( this.weight <= 9 ) { this.price = 2.66; } else if ( this.weight <= 10 ) { this.price = 2.87; } else if ( this.weight <= 11 ) { this.price = 3.08; } else if ( this.weight <= 12 ) { this.price = 3.29; } else if ( this.weight <= 13 ) { this.price = 3.5; } else { System.out.println("The maximum weight on Envelope is 13 ounce."); System.exit(0); } System.out.println("Your postage will be: " + "$" + this.price); } }