First, you can totally eliminate the second logic condition. Just say if (packages > 9) give the discount.
Second, I like keeping everything String until you need the math. Here, I banged this out. Please use it to study with. I could have put even more methods() into it to keep the logic clean and distinct from the math.
public class SSales {
static final int UNIT_PRICE = 99;
public SSales() {
intro();
}
public static void main(String[] args ) {
new SSales();
}
private void intro() {
Scanner sc = new Scanner(System.in);
double discountFactor = 0.0;
String[] liner = {
"---------",
"SOFTWARE SALES"};
System.out.printf(
"%-10s %14s %10s%n%n",
liner[0],liner[1],liner[0]);
System.out.printf(
"Please enter the number of packages"
+" that are being purchased.");
String qty = sc.nextLine();
if( validateInt( qty)) {
int numPurch = Integer.valueOf(qty);
if( numPurch > 10) {
System.out.printf("%s%n","Big Discount");
discountFactor = .02;
}
if( numPurch > 1 && numPurch <= 9) {
System.out.printf("s%n", "Good Ole Boy discount");
discountFactor = .01;
}
if( numPurch == 1) {
System.out.printf("%s%n","Remind them about the volume discounts");
discountFactor = .00;
}
System.out.printf( "%-23s%4d%n",
"Quantity Purchased: ", numPurch);
System.out.printf("%-21s$%2d.00%n", "Each at:",UNIT_PRICE);
double subTot = (UNIT_PRICE * numPurch);
double disc = (UNIT_PRICE * numPurch) * discountFactor;
System.out.printf("%-17s$%9.2f%n", "Sub-total",subTot);
if( discountFactor > 0.00) {
System.out.printf( "%-23s%.2f%% %n","Discount",discountFactor);
System.out.printf("%-16s-$%9.2f%n", "Less Discount:",disc );
}
System.out.printf("%-17s$%9.2f%n","Total Amt. Due:", (subTot - disc ));
System.out.printf("%s%s%s%n%n",liner[0],liner[0],liner[0]);
}
}
private boolean validateInt( String quantity ) {
try {
Integer.parseInt(quantity);
return true;
} catch (Exception e) {
return false;
}
}
}