Blog

Coursehelp
March 15, 2019
QUESTION : No Comments

(Solved) : Program Required Write Java Program Implement Data Structure Called Refrigerator Test Impl Q17903264

In this program, you are required to write a Java program toimplement a data structure, called, a “Refrigerator” and test yourimplementation. We all know that a refrigerator is a cooling devicethat holds many items, say N.

A refrigerator object is stored as an array of integers wherethe value of the element at index i contains the number ofoccurrences of the ith item in that refrigerator. For example, thecollection of items {1,3,5,4,7,3,1,5,4,3,2,8,4,3,9} forms aperfectly valid refrigerator in which item 3 appears four times.This specific refrigerator array will look like…

Index — 1 2 3 4 5 6 7 8 9 10 11 12 —–
Value — 2 1 4 3 2 0 1 1 1 0 0 0 —–

You are required to implement the following operations on aRefrigerator.

1.   Constructor: Initializes the refrigerator to bean empty one. (All values in the array = 0)
2.   is_empty: Returns true if the refrigerator iscompletely empty; false, otherwise.
3.   insert_item: Takes in an item and places it in therefrigerator.
4.   delete_item: Takes in an item and deletes oneoccurrence of that item (if it exists) in the refrigerator.
5.   find_it: Takes in an item and returns true if theitem is present in the refrigerator at least once; false,otherwise.
6.   combine: Takes in two refrigerators and returns thecombined refrigerator. For example, if one had 3 MILKs and theother had 5 MILKs, then the combination has 8 MILKs.
7.   common_items: Takes in two refrigerators and returnsthe common items in them as the refrigerator. For example, if onehad 3 MILKs and the other had 5 MILKs, then the common number ofMILKs in the result refrigerator is 3.
8.   output_refrigerator: Outputs the items of therefrigerator. Multiple occurrences are output appropriately to showhow many times that item occurs in the refrigerator. For example,the output for the above refrigerator is …
1 1 2 3 3 3 3 4 4 4 5 5 7 8 9

To test that your implementation works, write a main method asinstructed below. All input MUST BE read from an input file whosename is given by the user (no hard coding of the file names in yourprogram is allowed). The user also provides the name of the outputfile where the output of your program will be produced.

Create an array of refrigerators (the first input data is themaximum number of refrigerators), called R. R[i] refers to ithrefrigerator. Just for the hack of it, do not use R[0]. The seconddata item in the input file is the maximum number of differentitems stored in a refrigerator.

Beyond this, the input file contains the operation to beperformed, one line per operation. Let’s assume that a singlecharacter read from input file identifies which of the above sevenoperations needs to be performed (Constructor is invokedautomatically). Let these characters respectively be,
   E I D F C M O
i.e., D indicates “delete an element” operation, M indicates”perform the common-items operation”, etc.
For example,

I 1 3 — Insert item 1 in refrigerator 3.
D 3 6 — Delete item 3 from refrigerator 6.
E 2 — Is R[2] empty ?
F 5 7 — Is item 5 in R[7] ?
C 6 4 5 — R[5] := Combination of R[6] and R[4].
M 5 3 2 — R[2] := Common items of R[5] and R[3]
O 1 — Output the contents of R[1].

The main program just reads in the operation codes correspondingto the operations to be performed, and uses the class to performthem.

It is very important that after doing each operation, youmention in the output, what operation was performed and what arethe contents of the altered refrigerator, wherever appropriate; orwhat is the result of the query. The output must be completelyself-explanatory and must be produced in an output file whose nameis provided by the user.

input.txt

7 // Maximum Number of refrigerators12 // Maximum Number of itemsE 1E 11I 2 1I 3 1I 4 1I 4 1I 7 1I 8 1I 7 1I 1 1I 3 1I 5 1I 6 1I 6 1I 4 1I 6 2I 8 2I 9 2I 11 2I 11 2I 12 2I 1 2I 3 2I 2 2I 3 2I 1 2I 5 2I 3 2E 2D 11 2D 10 1D 6 1F 12 1F 4 2F 2 2F 1 1F 10 2C 1 2 3M 1 2 4C 3 4 5M 3 4 6C 1 1 7O 1O 2O 3O 4O 5O 6O 7

How to input the text file

import java.io.FileReader;import java.io.PrintWriter;import java.util.Scanner;import javax.swing.JOptionPane;public class fileIO { public static void main (String[] args) throws Exception { String inf = JOptionPane.showInputDialog(“Input file?”); // Input file is src/<name of the file> FileReader inFile = new FileReader(inf); Scanner in = new Scanner(inFile); String outf = JOptionPane.showInputDialog(“Output file?”); PrintWriter outFile = new PrintWriter(outf); while (in.hasNextLine()) { String line = in.nextLine(); outFile.println(line+”n”); } outFile.close(); }}

Expert Answer


Attached . . .

OR
OR

Have a Comment on this Question?

Questions viewed by other students


  • QUESTION : (Solved) : 12 Use Code Answer Questions Follow Assume Proper Libraries Name Spaces Included Code Comp Q31043595

    This is in c++

    12. Use the code below to answer the questions that follow. Assume that all proper libraries and name spaces are included and that the code will compile without error. Within the main function, for the variable int last_sid write in the last digit of your SMC student ID. int foo(int a, int b)f //First intc- a+b; while(c>-3) return C; char foo(string a, int b) t //Second return a[b]; string foo(int b, string &a) 1 //Third string sub-a.substr (3*b,3); a.replace (3*b,3,...); return sub; void main() int last sid - string letters(ggfiorkcboneat !! !ws adtarojot); string output(); int numbers[] {0,8,3,7,4,6,9,1,2,5}; ; //<-Last digit of your SID for(int i-0; i<10; i++) [ int j - numbers[i]; numbers [i]-foo(last_sid,i); string s-foo(j, letters); output -foo(s, numbers[i]); cout << output; a.) For each of the three foo functions briefly describe in plain language what each function is doing. You may refer to the top function as the first function, the one below as the second function, and finally the last as the third function. b.) What is it called when we use the same function identifier for multiple functions? What must we done to allow the compiler to differentiate between functions with the same identifier?

    12. Use the code below to answer the questions that follow. Assume that all proper libraries and name spaces are included and that the code will compile without error. Within the main function, for the variable int last_sid write in the last digit of your SMC student ID. int foo(int a, int b)f //First intc- a+b; while(c>-3) return C; char foo(string a, int b) t //Second return a[b]; string foo(int b, string &a) 1 //Third string sub-a.substr (3*b,3); a.replace (3*b,3,”…”); return sub; void main() int last sid – string letters(“ggfiorkcboneat !! !ws adtarojot”); string output(“”); int numbers[] {0,8,3,7,4,6,9,1,2,5}; ; //Show transcribed image text

    Expert Answer


    Attached . . .


    view full answer
  • QUESTION : (Solved) : 12 Use Direct Proof Show Following Argument Valid Need Add Lines Finish Proof First Box Pr Q28206669

    12.

    Use a direct proof to show that the following argument isvalid.

    Need to add the lines to finish the proof. The first box shouldbe the proof, second two boxes should reference the line numbers,the last box should say which rule we are using. Thank you inadvance!!

    1 (F.K) 2 (B V ~K) 3C (FVB) NC 4 Check Modus Ponens MP Modus Tollens MT Hypothetical Syllogism HS Disjunctive Syllogism DS Constructive Dilemma CD Simplification Simp Conjunction Conj Addition Add DeMorgans Rule DM Commutativity Com Associativity Assoc Distribution Dist Double Negation DN Add Line X Delete Line Check Proof

    1 (F.K) 2 (B V ~K) 3C (FVB) NC 4 Check Modus Ponens MP Modus Tollens MT Hypothetical Syllogism HS Disjunctive Syllogism DS Constructive Dilemma CD Simplification Simp Conjunction Conj Addition Add DeMorgan’s Rule DM Commutativity Com Associativity Assoc Distribution Dist Double Negation DN Add Line X Delete Line Check Proof Show transcribed image text 1 (F.K) 2 (B V ~K) 3C (FVB) NC 4 Check Modus Ponens MP Modus Tollens MT Hypothetical Syllogism HS Disjunctive Syllogism DS Constructive Dilemma CD Simplification Simp Conjunction Conj Addition Add DeMorgan’s Rule DM Commutativity Com Associativity Assoc Distribution Dist Double Negation DN Add Line X Delete Line Check Proof

    Expert Answer


    Attached . . .


    view full answer
  • QUESTION : (Solved) : 12 Using Table Shown Process Time Diagram Schedule Processes P1 P2 P3 100 Time Units Using Q28960003

    12. Using the table shown below and with the process-time diagram, schedule the processes P1, P2, and P3 for 100 time units using the below scheduling techniques. Assume there is only one CPU and CPU schedules the processe:s repeatedly based on the below conditions. a. Round-Robin scheduling. Assume for all processes, there is no period and no priority and all processes are ready at t-0. (5 Points) b. Priority-Driven scheduling (15 Points) c. Rate Monotonic Scheduling. Do not use the priority given in the table. (10 Points) ProcessExecution Time PeriodReady Priority P1 P2 P3 10 15 200 20 25 30 0 10 2

    12. Using the table shown below and with the process-time diagram, schedule the processes P1, P2, and P3 for 100 time units using the below scheduling techniques. Assume there is only one CPU and CPU schedules the processe:s repeatedly based on the below conditions. a. Round-Robin scheduling. Assume for all processes, there is no period and no priority and all processes are ready at t-0. (5 Points) b. Priority-Driven scheduling (15 Points) c. Rate Monotonic Scheduling. Do not use the priority given in the table. (10 Points) ProcessExecution Time PeriodReady Priority P1 P2 P3 10 15 200 20 25 30 0 10 2 Show transcribed image text

    Expert Answer


    Attached . . .


    view full answer