(Solved) : Package Comcompany Import Javautilrandom Public Class Box Static Factory Method Called Cre Q41336897 . . .

package com.company;
import java.util.Random;
public class Box {
// static factory method called to create Box instanceobjects// with random values for weight, value and contentspublic static Box randomBox() {String[] contents = {“apples”, “oranges”, “lemons”, “bread”,”sugar”};Random r = new Random();return new Box(r.nextDouble()*100, r.nextDouble() * 50,contents[r.nextInt(contents.length)]);}
private double weight = 1;private double value = 1;private String contents = “nothing”;
public Box() { }
public Box(double weight, double value, String contents){if (weight > 1)this.weight = weight;if (value > 1)this.value = value;this.contents = contents;}
public double getWeight() {return weight;}
public double getValue() {return value;}
public String getContents() {return contents;}}

package com.company; import java.util.Random; public class Box { // static factory method called to create Box instance objecΛΛΛΛΛΛΛΛΛΛ THIS IS “Box.Java” THIS IS “Box.Java” THIS IS Box.Java THIS IS Box.Java”Box.java is the strip of code | Gave at the top// that was created by Intellij, entirely my own work, but I received some assistance from {name}. // Follow this with a descv. Now Box is a class in the package. Ele Edit View Blog de Ana Bracho d e s S Wide pa sample com company Project - wi j EpamIt is a good idea to become acquainted with class Box by creating instance objects and reference variables in method main of6. In class Main, write the Java code to complete the project. Your user interface solution code may include as much code inEnter the capacity of container 0 (>2): 3 Enter the capacity of container 1 (>2): 4 Enter the capacity of container 2 (>2): 31-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-2, Max Boxes-4 Container 2: Boxes-1, Max Boxes-3
Tips Strings can be concatenated (+) in a loop. I. e., an existing string can be appended to over and over, making a larger a
Box.java is the strip of code | Gave at the top
Box.java is the strip of code | Gave at the toppackage com.company; import java.util.Random; public class Box { // static factory method called to create Box instance objects // with random values for weight, value and contents public static Box randomBox() { String contents = {‘apples”, “oranges”, “lemons”, “bread”, “sugar”); Random r = new Random(); return new Box (r.nextDouble()*100, r.nextDouble() * 50, contents(r.nextInt (contents.length)]); private double weight = 1; private double value = 1; private String contents = “nothing”; public Box() { } public Box(double weight, double value, String contents) { if (weight > 1) this.weight = weight; if (value > 1) this.value = value; this.contents = contents; public double getWeight() { return weight; public double getValue() { return value; public String getContents() { return contents; ΛΛΛΛΛΛΛΛΛΛ THIS IS “Box.Java” THIS IS “Box.Java” THIS IS “Box.Java” THIS IS “Box.Java” Box.java is the strip of code | Gave at the top // that was created by Intellij, entirely my own work, but I received some assistance from {name}. // Follow this with a description of the type of assistance. (For example, if you consulted a book, and // your solution incorporates ideas found in the book, give appropriate credit; that is, include a // bibliographical reference.) Note: You do not have to list the text, the author of the course text or // the instructors examples. 3. Insert the provided file “Box.java” into your project. i. Download “Box.java” from Moodle. ii. Locate and copy “Box.java”. iii. In your IntelliJ project, right click (two finger touch on Apple touch pads) on the package containing file “Main.java” and paste “Box.java’ into the package. File Tools Vcs Window Help Edit View Navigate Code Analyze Refactor Build Run pal_example sc com company Project – – pad example/classes/260/2019 fallrassignmentsip 1 Main.java package con.company: E public class Main mainis SIC becom.company e Main pa4_example.ml External Libraries Scratches and Consoles New X cus here Ctrl В соо Ctrl Ctrl+Shift Ctrle Alt+Shift+ Copy Path Copy Reference Paste Find Usages Alt+F7 iv. In the Copy Class dialog, click OK. IntelliJ will insert the correct package name in the code of “Box.java” Copy Class Copy class com.company.Box New name: во Destination package: com.company Open copy in editor OK Cancel Help v. Now Box is a class in the package. Ele Edit View Blog de Ana Bracho d e s S Wide pa sample com company Project – wi j Epamples package com.com porttitor public class Box wanges ” String contents- run bol ” . , . r”: contratantes length; . private de wet-1: private d e a -1 prie Scott public Boxidable weight, double String contents weight this IF value this w a port: public double raw ) 4. Exploring the given class Box Open “Box.java” and examine class Box. The purpose of class Box is to model a simple shipping box. Private data members consist of the weight, the monetary value of the contents and the description of the contents. Class Box is an immutable class as the values of the fields in an instance object of class Box cannot be changed after the constructor is called. Le, there are no “setter” methods in class Box and all the fields are marked private. A factory method is a method that when called, creates and returns an instance object of the containing class. I. e. the factory method calls the constructor with common parameters so that the programmer using the class does not have to call the constructor in most or any cases. Factory methods are often regarded as pseudo-constructors of convenience. However, if in fact the factory method is to be used exclusively to create instance objects, the constructors of the class are marked private to prevent them from being called. (Note that this is not the case in class Box, where there is a factory method and public constructors.) Class Box contains the factory method public static Box randomBox(). When called, method randomBox receives nothing, creates a class Box instance object with a weight in the range (0,100), a monetary value in the range of (0,50) and a contents description of one of five values (“apples”, “oranges”, “lemons”, “bread” or “sugar”). Once the Box instance object is created with values, the reference to the Box instance object is then returned. As it is static, randomBox can be called by use of the class name from outside the class as in the following example: Box b = Box.randomBox(); It is a good idea to become acquainted with class Box by creating instance objects and reference variables in method main of class Main and use the referenced variables to call the methods of class Box. Once you are familiar with using class Box, the code you created in method main can be deleted. 5. Modeling a “real world” Object in a Class that you will create The real world object to be modeled in a class is a simple shipping container that may contain boxes. This class must reside in your project in a file of its own. All boxes are the same size, but are of varying weight, value and contents. Simple shipping containers come in various sizes, l. e. can hold a specific number of boxes that is determined when the container is created. The container class must have the following private data members: • An array of class Box with the number of elements set to the value of a parameter passed to a constructor, but must have a minimum of at least 3 elements. • A variable to keep track of the number of boxes actually stored in the array of type Box. The container class must have a parametrized constructor and a default (no parameter) constructor The container class must have public methods to • return true if the container is full, false otherwise. • return the number of boxes actually stored in the container. • return the maximum number of boxes that can be stored in the container. insert a box into the container, i.e. add a box to the array. • return the total monetary value of the contents of all the boxes in the container. • return the total weight of the contents in all the boxes in the container. • return a string containing the manifest of the container, i.e. a list of the contents, weight and value of each box, as a formatted string. See Tips on the last page of this document. All data in the container class must be stored in the container class. I. e. the array of boxes is not passed in or out of the class, the number of boxes actually stored in the array can not be set from outside the class and the contents of the array can only be accessed from outside the class using the public methods provided in the class. It is good idea to test your container class by creating a reference variable referencing an instance object of the container class in method main of class Main, then use that reference variable to call the methods of the container class. Once you are comfortable that everything in the container class works, the code you created in method main can be deleted. 6. In class Main, write the Java code to complete the project. Your user interface solution code may include as much code in method main of class Main and / or as many methods in class Main as required. Write a job simulator for a system that loads boxes into shipping containers using the container class you have created and the given class Box as data types, plus calls to method randomBox to create instance objects of class Box. The job simulator will test users for their ability to distribute or reject boxes of goods and if they user can distribute the boxes correctly among multiple shipping containers. The simulator should: • Create three containers using the Container class to create three instance objects. • Show the rules to the user at program start. These are The user will place fruit in the proper containers. Boxes of apples should all go in one container. Boxes of oranges should go in one container. Boxes of lemons should go in one container. It is up to the user to select a container for each type of fruit. It is also up to the user to remember which container receives which fruit. ► All other boxes should be discarded. The program will run until the user elects to stop. The run will consist of repeatedly doing the following The user is prompted to choose to receive a new randomly created box or halt the program. If the user chooses to get a new box, a box is created with a call to the factory method randomBox of class Box. The user is then shown the status of the containers and the contents of the new box. The status of a container consists of the container number or name, the number of boxes stored in the container and the maximum number of boxes the container can store. The user in prompted to chose a container in which to place the box or to discard the box. If the user decides to place the box in the container, the box is added to the chosen container if there is room. As the containers do not test for the appropriate contents of a box, nor does the status of the container shown to the user indicate the contents of the boxes in the containers, it is up to the user to remember which container gets which fruit. • When the user elects to stop the program, the manifests of each container will be output Example Run (with user input shown in red). Should this user get the job? Add the boxes to the correct container, discarding any boxes that belong to a container that is full or a box that does not belong to any container. Apples go in one container, oranges go in another container and lemons go in yet another container. It does not matter which container contains a particular type of fruit, but a container must contain only one type of fruit. It is up to you to remember which container is correct. Discard boxes that contain any other items. Enter the capacity of container 0 (>2): 3 Enter the capacity of container 1 (>2): 4 Enter the capacity of container 2 (>2): 3 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-0, Max Boxes-4 Container 2: Boxes-o, Max Boxes-3 New Box: apples Place in container number? (-1 discards box) 1 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-1, Max Boxes-4 Container 2: Boxes-0, Max Boxes-3 New Box: lemons Place in container number? (-1 discards box) 3 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-1, Max Boxes-4 Container 2: Boxes-o, Max Boxes-3 New Box: oranges Place in container number? (-1 discards box) 2 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-1, Max Boxes-4 Container 2: Boxes-1, Max Boxes-3 New Box: bread Place in container number? (-1 discards box) -1 HD iH 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-1, Max Boxes-4 Container 2: Boxes-1, Max Boxes-3 New Box: oranges Place in container number? (-1 discards box) 1 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-2, Max Boxes-4 Container 2: Boxes-1, Max Boxes-3 New Box: sugar Place in container number? (-1 discards box) -1 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-2, Max Boxes-4 Container 2: Boxes-1, Max Boxes-3 New Box: apples Place in container number? (-1 discards box) O 1-get a box, 2-halt): 1 Container 0: Boxes-1, Max Boxes-3 Container 1: Boxes-2, Max Boxes-4 Container 2: Boxes-1, Max Boxes-3 New Box: lemons Place in container number? (-1 discards box) 2 1-get a box, 2-halt): 1 Container 0: Boxes-1, Max Boxes-3 Container 1: Boxes-2, Max Boxes-4 Container 2: Boxes-2, Max Boxes-3 New Box: apples Place in container number? (-1 discards box) O 1-get a box, 2-halt): 1 Container 0: Boxes-2, Max Boxes-3 Container 1: Boxes-2, Max Boxes-4 Container 2: Boxes-2, Max Boxes-3 New Box: apples Place in container number? (-1 discards box) O 1-get a box, 2-halt): 2 Container O manifest: Contents Weight apples 43.16 apples 65.42 apples 57.49 Value 32.98 27.48 8.94 Container i manifest: Contents Weight apples 84.44 oranges 39.36 Value 32.53 19.65 Container 2 manifest: Contents Weight oranges 11.90 lemons 25.22 Value 37.48 1.36 Tips Strings can be concatenated (+) in a loop. I. e., an existing string can be appended to over and over, making a larger and larger string. String class has a static format function that returns a string formated in the same way that System.out.printf formats strings. Example: String s = “Random Number Listn”; for (int i = 0; i < 5; i++) S += String.format(“number #%d %10.2fn”, i, Math.random() * 100); System.out.println(s); Sample run: Random Number List number #0 17.02 number #1 30.03 number #2 8.58 number #3 90.86 number #4 29.45 Additional Requirements (a) Class Box is to be used “as is” and not changed in any way other than insertion of the correct package statement. (b) A reference variable and instance object of class java.util.Scanner must be used to read the input from the user. (C) Identifiers must be descriptive, i. e. must self document. (d) Indention of all code blocks (compound statements, anything in braces), including single statements following selection or while statements, is required. Box.java is the strip of code | Gave at the top Box.java is the strip of code | Gave at the top Show transcribed image text package com.company; import java.util.Random; public class Box { // static factory method called to create Box instance objects // with random values for weight, value and contents public static Box randomBox() { String contents = {‘apples”, “oranges”, “lemons”, “bread”, “sugar”); Random r = new Random(); return new Box (r.nextDouble()*100, r.nextDouble() * 50, contents(r.nextInt (contents.length)]); private double weight = 1; private double value = 1; private String contents = “nothing”; public Box() { } public Box(double weight, double value, String contents) { if (weight > 1) this.weight = weight; if (value > 1) this.value = value; this.contents = contents; public double getWeight() { return weight; public double getValue() { return value; public String getContents() { return contents;
ΛΛΛΛΛΛΛΛΛΛ THIS IS “Box.Java” THIS IS “Box.Java” THIS IS “Box.Java” THIS IS “Box.Java”
Box.java is the strip of code | Gave at the top
// that was created by Intellij, entirely my own work, but I received some assistance from {name}. // Follow this with a description of the type of assistance. (For example, if you consulted a book, and // your solution incorporates ideas found in the book, give appropriate credit; that is, include a // bibliographical reference.) Note: You do not have to list the text, the author of the course text or // the instructors examples. 3. Insert the provided file “Box.java” into your project. i. Download “Box.java” from Moodle. ii. Locate and copy “Box.java”. iii. In your IntelliJ project, right click (two finger touch on Apple touch pads) on the package containing file “Main.java” and paste “Box.java’ into the package. File Tools Vcs Window Help Edit View Navigate Code Analyze Refactor Build Run pal_example sc com company Project – – pad example/classes/260/2019 fallrassignmentsip 1 Main.java package con.company: E public class Main mainis SIC becom.company e Main pa4_example.ml External Libraries Scratches and Consoles New X cus here Ctrl В соо Ctrl Ctrl+Shift Ctrle Alt+Shift+ Copy Path Copy Reference Paste Find Usages Alt+F7 iv. In the Copy Class dialog, click OK. IntelliJ will insert the correct package name in the code of “Box.java” Copy Class Copy class com.company.Box New name: во Destination package: com.company Open copy in editor OK Cancel Help
v. Now Box is a class in the package. Ele Edit View Blog de Ana Bracho d e s S Wide pa sample com company Project – wi j Epamples package com.com porttitor public class Box wanges ” String contents- run bol ” . , . r”: contratantes length; . private de wet-1: private d e a -1 prie Scott public Boxidable weight, double String contents weight this IF value this w a port: public double raw ) 4. Exploring the given class Box Open “Box.java” and examine class Box. The purpose of class Box is to model a simple shipping box. Private data members consist of the weight, the monetary value of the contents and the description of the contents. Class Box is an immutable class as the values of the fields in an instance object of class Box cannot be changed after the constructor is called. Le, there are no “setter” methods in class Box and all the fields are marked private. A factory method is a method that when called, creates and returns an instance object of the containing class. I. e. the factory method calls the constructor with common parameters so that the programmer using the class does not have to call the constructor in most or any cases. Factory methods are often regarded as pseudo-constructors of convenience. However, if in fact the factory method is to be used exclusively to create instance objects, the constructors of the class are marked private to prevent them from being called. (Note that this is not the case in class Box, where there is a factory method and public constructors.) Class Box contains the factory method public static Box randomBox(). When called, method randomBox receives nothing, creates a class Box instance object with a weight in the range (0,100), a monetary value in the range of (0,50) and a contents description of one of five values (“apples”, “oranges”, “lemons”, “bread” or “sugar”). Once the Box instance object is created with values, the reference to the Box instance object is then returned. As it is static, randomBox can be called by use of the class name from outside the class as in the following example: Box b = Box.randomBox();
It is a good idea to become acquainted with class Box by creating instance objects and reference variables in method main of class Main and use the referenced variables to call the methods of class Box. Once you are familiar with using class Box, the code you created in method main can be deleted. 5. Modeling a “real world” Object in a Class that you will create The real world object to be modeled in a class is a simple shipping container that may contain boxes. This class must reside in your project in a file of its own. All boxes are the same size, but are of varying weight, value and contents. Simple shipping containers come in various sizes, l. e. can hold a specific number of boxes that is determined when the container is created. The container class must have the following private data members: • An array of class Box with the number of elements set to the value of a parameter passed to a constructor, but must have a minimum of at least 3 elements. • A variable to keep track of the number of boxes actually stored in the array of type Box. The container class must have a parametrized constructor and a default (no parameter) constructor The container class must have public methods to • return true if the container is full, false otherwise. • return the number of boxes actually stored in the container. • return the maximum number of boxes that can be stored in the container. insert a box into the container, i.e. add a box to the array. • return the total monetary value of the contents of all the boxes in the container. • return the total weight of the contents in all the boxes in the container. • return a string containing the manifest of the container, i.e. a list of the contents, weight and value of each box, as a formatted string. See Tips on the last page of this document. All data in the container class must be stored in the container class. I. e. the array of boxes is not passed in or out of the class, the number of boxes actually stored in the array can not be set from outside the class and the contents of the array can only be accessed from outside the class using the public methods provided in the class. It is good idea to test your container class by creating a reference variable referencing an instance object of the container class in method main of class Main, then use that reference variable to call the methods of the container class. Once you are comfortable that everything in the container class works, the code you created in method main can be deleted.
6. In class Main, write the Java code to complete the project. Your user interface solution code may include as much code in method main of class Main and / or as many methods in class Main as required. Write a job simulator for a system that loads boxes into shipping containers using the container class you have created and the given class Box as data types, plus calls to method randomBox to create instance objects of class Box. The job simulator will test users for their ability to distribute or reject boxes of goods and if they user can distribute the boxes correctly among multiple shipping containers. The simulator should: • Create three containers using the Container class to create three instance objects. • Show the rules to the user at program start. These are The user will place fruit in the proper containers. Boxes of apples should all go in one container. Boxes of oranges should go in one container. Boxes of lemons should go in one container. It is up to the user to select a container for each type of fruit. It is also up to the user to remember which container receives which fruit. ► All other boxes should be discarded. The program will run until the user elects to stop. The run will consist of repeatedly doing the following The user is prompted to choose to receive a new randomly created box or halt the program. If the user chooses to get a new box, a box is created with a call to the factory method randomBox of class Box. The user is then shown the status of the containers and the contents of the new box. The status of a container consists of the container number or name, the number of boxes stored in the container and the maximum number of boxes the container can store. The user in prompted to chose a container in which to place the box or to discard the box. If the user decides to place the box in the container, the box is added to the chosen container if there is room. As the containers do not test for the appropriate contents of a box, nor does the status of the container shown to the user indicate the contents of the boxes in the containers, it is up to the user to remember which container gets which fruit. • When the user elects to stop the program, the manifests of each container will be output Example Run (with user input shown in red). Should this user get the job? Add the boxes to the correct container, discarding any boxes that belong to a container that is full or a box that does not belong to any container. Apples go in one container, oranges go in another container and lemons go in yet another container. It does not matter which container contains a particular type of fruit, but a container must contain only one type of fruit. It is up to you to remember which container is correct. Discard boxes that contain any other items.
Enter the capacity of container 0 (>2): 3 Enter the capacity of container 1 (>2): 4 Enter the capacity of container 2 (>2): 3 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-0, Max Boxes-4 Container 2: Boxes-o, Max Boxes-3 New Box: apples Place in container number? (-1 discards box) 1 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-1, Max Boxes-4 Container 2: Boxes-0, Max Boxes-3 New Box: lemons Place in container number? (-1 discards box) 3 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-1, Max Boxes-4 Container 2: Boxes-o, Max Boxes-3 New Box: oranges Place in container number? (-1 discards box) 2 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-1, Max Boxes-4 Container 2: Boxes-1, Max Boxes-3 New Box: bread Place in container number? (-1 discards box) -1 HD iH 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-1, Max Boxes-4 Container 2: Boxes-1, Max Boxes-3 New Box: oranges Place in container number? (-1 discards box) 1 1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-2, Max Boxes-4 Container 2: Boxes-1, Max Boxes-3 New Box: sugar Place in container number? (-1 discards box) -1
1-get a box, 2-halt): 1 Container 0: Boxes-0, Max Boxes-3 Container 1: Boxes-2, Max Boxes-4 Container 2: Boxes-1, Max Boxes-3 New Box: apples Place in container number? (-1 discards box) O 1-get a box, 2-halt): 1 Container 0: Boxes-1, Max Boxes-3 Container 1: Boxes-2, Max Boxes-4 Container 2: Boxes-1, Max Boxes-3 New Box: lemons Place in container number? (-1 discards box) 2 1-get a box, 2-halt): 1 Container 0: Boxes-1, Max Boxes-3 Container 1: Boxes-2, Max Boxes-4 Container 2: Boxes-2, Max Boxes-3 New Box: apples Place in container number? (-1 discards box) O 1-get a box, 2-halt): 1 Container 0: Boxes-2, Max Boxes-3 Container 1: Boxes-2, Max Boxes-4 Container 2: Boxes-2, Max Boxes-3 New Box: apples Place in container number? (-1 discards box) O 1-get a box, 2-halt): 2 Container O manifest: Contents Weight apples 43.16 apples 65.42 apples 57.49 Value 32.98 27.48 8.94 Container i manifest: Contents Weight apples 84.44 oranges 39.36 Value 32.53 19.65 Container 2 manifest: Contents Weight oranges 11.90 lemons 25.22 Value 37.48 1.36
Tips Strings can be concatenated (+) in a loop. I. e., an existing string can be appended to over and over, making a larger and larger string. String class has a static format function that returns a string formated in the same way that System.out.printf formats strings. Example: String s = “Random Number Listn”; for (int i = 0; i

Expert Answer


Answer to package com.company;import java.util.Random;public class Box { // static factory method called to create Box instance ob…