/** A Letter class to handle Letter only * * @author Freeman Lo * @version 0.0.1 Build 1 Jan 28, 2014. * */ import java.io.*; import java.util.*; import java.lang.*; class Letter { private double weight; private double price; public Letter() { 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 = .49; } else if ( this.weight <= 2 ) { this.price = .70; } else if ( this.weight <= 3 ) { this.price = .91; } else if ( this.weight <= 3.5 ) { this.price = 1.12; } else { System.out.println("The maximum weight on Letter is 3.5 ounce."); System.exit(0); } System.out.println("Your postage will be: " + "$" + this.price); } }