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

Your Community Supported Agriculture (CSA) farm delivers a box of fresh fruits a

ID: 3531964 • Letter: Y

Question

Your Community Supported Agriculture (CSA) farm delivers a box of fresh fruits and vegetables to your house once a week. For this Programming Project, define the class BoxOfProduce that contains exactly three bundles of fruits or vegetables. You can represent the fruits or vegetables as three instance variables of type String. Add an appropriate constructor, accessor, and mutator methods. Also write a toString() method that returns as a String the complete contents of the box.

Next, write a main method that creates a BoxOfProduce with three items randomly selected from this list:

This list should be stored in a text file that is read in by your program. For now you can assume that the list contains exactly five types of fruits or vegetables.

Do not worry if your program randomly selects duplicate produce for the three items. Next, the main method should display the contents of the box and allow the user to substitute any one of the five possible fruits or vegetables for any of the fruits or vegetables selected for the box. After the user is done with substitutions, output the final contents of the box to be delivered. If you create additional meth- ods to select the random items and to select valid substitutions, then your main method will be simpler to write.

In java please!

Explanation / Answer

public static void main(String[] args) throws InterruptedException { List my_words = new LinkedList(); my_words.add("brocolli"); my_words.add("tomatto"); my_words.add("kiwi"); my_words.add("kale"); my_words.add("tomatillo"); Random rand = new Random(); while (true) { int choice = rand.nextInt(my_words.size()); System.out.println("Choice = " + my_words.get(choice)); Thread.sleep(1000); int replaceTo = rand.nextInt(my_words.size()); System.out.println("Replace to = " + my_words.get(replaceTo)); my_words.set(choice, my_words.get(replaceTo)); } } //above will choose random string from the given set //now adding it to a given thread try { //create a buffered reader that connects to the console, we use it so we can read lines BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //read a line from the console String lineFromInput = in.readLine(); //create an print writer for writing to a file PrintWriter out = new PrintWriter(new FileWriter("output.txt")); //output to the file a line out.println(lineFromInput); //close the file (VERY IMPORTANT!) out.close(); } catch(IOException e1) { System.out.println("Error during reading/writing");
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