Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A smal needed to ship book orders without wasting space. There are four types of

ID: 3916162 • Letter: A

Question

A smal needed to ship book orders without wasting space. There are four types of boxes: extra-large, large, medium and small, which holds 25, 15, 5 and 1 book(s), respectively. Write a Jata program that accepts the number of books to be shipped, and displays the number of individual boxes along with their type, as well as the total number of boxes needed. For example if the company wants to ship 81 books rour output should be 3 extra-large boxes, 1 medium box and 1 small box, a total of 5 boxes. company wants you to wite a program to find the number of boxes Use the following class diagram as the basis for your solution. PackingBooks -books: int xlarge: int -large int -medium: int -small int totalint +PackingBooks booksint) getXLargeBoxOint -getLargeBoxO- int getlediumBox0: int +getSmallBox0: int ?getTotalBoxesQ: int +determineBoxes: roid Hint Define an algorithm for the method determineBoxes before writing the code. This is the only method necessary for determining the number of boxes needed.

Explanation / Answer

class PackingBooks

{

final int XTRA_LARGE_BOX = 25;

final int LARGE_BOX = 15;

final int MEDIUM_BOX = 5;

private int books;

private int xlarge;

private int large;

private int medium;

private int small;

private int total;

public PackingBooks(int books)

{

this.books = books;

xlarge = 0;

large = 0;

medium = 0;

small = 0;

total = 0;

}

public int getXLargeBox()

{

return xlarge;

}

public int getLargeBox()

{

return large;

}

public int getMediumBox()

{

return medium;

}

public int getSmallBox()

{

return small;

}

public int getTotalBox()

{

return total;

}

public void determineBoxes()

{

xlarge = books/XTRA_LARGE_BOX;

books = books%XTRA_LARGE_BOX;

large = books/LARGE_BOX;

books = books%LARGE_BOX;

medium = books/MEDIUM_BOX;

small = books%MEDIUM_BOX;

total = xlarge + large + medium + small;

}

}

public class TestPackingBooks

{

public static void main(String[] arg)

{

PackingBooks pack = new PackingBooks(127);

pack.determineBoxes();

System.out.println(pack.getXLargeBox() + " extra large boxes "

+ pack.getLargeBox() + " large boxes "

+ pack.getMediumBox() + " medium boxes "

+ pack.getSmallBox() + " small boxes "

+ pack.getTotalBox() + " total boxes ");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote