I want the program to check how many large boxes are needed, then use the remainder to determine how many medium boxes are needed and do the same for small boxes. But when i run this
in the first step to determine the large boxes
variable pensnotinbox comes out as 0 even though i know there should be a remainder
pen.setName("Awesome Pen");
pen.setPrice(5.0);
pen.setUPC(102);
pen.setMediumCapacity(50);
pen.setLargeCapacity(100);
//printing information about the product to the user, and asking how many of this item they want to purchase
System.out.print("Product 2 \n" + "Name:" + pen.getName() + " Price: " + pen.getPrice() + " UPC: " + pen.getUPC() + "\n");
System.out.print("How Many Of These Would You Like To Purchase?\n" );
//using the scanner to get the integer/quantity they want
penquant = scan.nextInt();
//storing the total price in a variable
int penlargeboxes;
double penboxes;
int penmediumboxes;
double penremainder;
double pensnotinbox;
int pensmallboxes;
if (pen.getLargeCapacity() <= penquant) {
penlargeboxes = penquant/pen.getLargeCapacity();
penremainder = penquant % pen.getLargeCapacity();
System.out.print(penlargeboxes + "\n");
System.out.print(penremainder + "\n");
if (penremainder > 0 ) {
penboxes = penremainder/pen.getMediumCapacity() ;
penmediumboxes = ((int)penboxes);
penremainder = penquant % pen.getLargeCapacity();
pensnotinbox = penremainder;
System.out.print(penmediumboxes + "\n");
System.out.print(pensnotinbox + "\n");
}else {
if (penremainder > .99 ) {
penboxes = penremainder/1 ;
pensmallboxes = ((int)penboxes);
System.out.print(pensmallboxes + "\n");
}
}
} else {
System.err.println("OOPS!");
}
pentotal= (pen.totalPurchase(penquant));
//printing their total cost for this item
System.out.print("The total cost for this item will be " + pentotal + "\n" + "\n");
doublewhen counting discrete units?doublehoweverpenquant/pen.getLargeCapacity()may use integer division meaning there is no fractional part. ;)