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) : Would Like Help Getting Code Question C Benchmarsk Sorting Methods Listed Using Visual St Q29139380 . . .

    I would like some help getting the code for the question belowin C++.

    Benchmarsk each of the sorting methods listed below using visualstudio.

    Insertion Sort, Bubble Sort Heap Sort. Quick Sort. MergeSort.

    Benchmark each of the above sorting methods for data sizes of10000, 20000, 30000, 40000 and 50000. Display the results in atable as shown below. The table should have rows and columns.However, the rows and columns need not be separated by lines.
      

    Data Size

    Heap Sort Time In Seconds

    Merge Sort Time In Seconds

    Quick Sort Time In Seconds

    Quadratic Sort Time In Seconds

    100000

    200000

    300000

    400000

    500000

    Notes:

    ? Do not use a local array for keeping data values. Use a globalarray for this purpose. You can use dynamically allocated arrays ifyou wish.

    Generate the data using a random generator and store it in aglobal array for use in sorting. If you use a local array of largesize, you will run out of stack space.

    ? Calculate the time taken by a sort routine in seconds asbelow:

    #include

    clock_t start, finish;
    start =clock( ); //time in milliseconds
    sort( );
    finish=clock( ); //time in milliseconds
    //the constant CLOCKS_PER_SEC below is equal to 1000
    double duration = (double) ( (finish-start)/CLOCKS_PER_SEC );//time in secs.

    Expert Answer


    . . .


    view full answer
  • QUESTION : (Solved) : Write Arm Assembly Language Routine Count Number 1s 32 Bit Word R0 Return Result R1 Code F Q34564596 . . .

    Write an ARM assembly language routine to count the number of 1sin a 32‐bit word in r0 and return the result in r1.

    code:

    LDR r0, 0x11AB003F dummy value for rl (11 ones) MOV r1,#0x0 MOV r2,#32 MOVS r0,r0, ROR #1 ADDCS r1,r1,#1 SUBS r2 , r2 , #1 BNE OnesCount ; clear ones counter ;use r2 as the loop counter i Repeat: rotate ro right set Ilags ;if carry set increment 1s counter ; decrement loop counter until all bits tested OnesCount If this was a subroutine Count, the code might be area test, cODE, readwrite ADR sp, Stackl LDR r2 , =0xFFFFFFFF STR r2, [sp] LDR r0, - 0xFFAB123A BL MOV r3,rl NOP NOP ;set up dummy r2 ; dummy data :call routine ; read result Count STMFD sp!, (r2,lr] MOV r1, #0x0 MOV r2,#4 Count ; save r2 and return on the stack onesCount MOVS r0,r0, ROR #1 ADDCS r1,r1,#1 SUBS r2 , r2 , #1 BNE OnesCount LDMFD sp!, (r2,pc) ; restore r2 and returr Stack Stackl DCD 0,0,0,0,0 DCD 0,0,0,0,0

    The following image is a screendump after executing the abovecode. Register r3 contains 0x13 which is 19, the
    number of 1s in 0x11AB003F.

    CAUsers AlanCore7 Desktop ForBrusselsMay2012Chap3Problems.uvproj - pVision4 File Edit iew Project Flash Debug Peripherals Tools SVCS Window Help Registers 3Chap3Problems.asm area test, CoDE, readwrite ADR p, Stackl LDR r2,=0xEEEEEEEE STR r2, [ap] LDR ro, - 0XEEAB123A ;dummy data BL Count MOV 3,rl B Parkilere RegisterValue0 Current OF FAB123A 0x00000013 :set up dumay x2 R1 000000013 call routine : read result endless loop R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 (5P) 0x00000054 R14 (LR) 000000014 R15 (PC) 000000018 0 ParkHere NOP 0 count STMED sp!, 2,1x) MOV Nov saver and return on the stacik r1, #0x0 r2, #32 13 onescount Movs ro,r0 , ROR #1 ADDcs r1,r1, #1 SUBS r2, r2, 1 BNE Onescount 15 restore r2 and return Stack DCD o,o, o, 0,0 User/System Fast Interrupt Interrupt 20 Stack DCD 0,0,0,0,0 21 END Project E Registers Simulation

    LDR r0, 0x11AB003F dummy value for rl (11 ones) MOV r1,#0x0 MOV r2,#32 MOVS r0,r0, ROR #1 ADDCS r1,r1,#1 SUBS r2 , r2 , #1 BNE OnesCount ; clear ones counter ;use r2 as the loop counter i Repeat: rotate ro right set Ilags ;if carry set increment 1s counter ; decrement loop counter until all bits tested OnesCount If this was a subroutine Count, the code might be area test, cODE, readwrite ADR sp, Stackl LDR r2 , =0xFFFFFFFF STR r2, [sp] LDR r0, – 0xFFAB123A BL MOV r3,rl NOP NOP ;set up dummy r2 ; dummy data :call routine ; read result Count STMFD sp!, (r2,lr] MOV r1, #0x0 MOV r2,#4 Count ; save r2 and return on the stack onesCount MOVS r0,r0, ROR #1 ADDCS r1,r1,#1 SUBS r2 , r2 , #1 BNE OnesCount LDMFD sp!, (r2,pc) ; restore r2 and returr Stack Stackl DCD 0,0,0,0,0 DCD 0,0,0,0,0 CAUsers AlanCore7 Desktop ForBrusselsMay2012Chap3Problems.uvproj – pVision4 File Edit iew Project Flash Debug Peripherals Tools SVCS Window Help Registers 3Chap3Problems.asm area test, CoDE, readwrite ADR p, Stackl LDR r2,=0xEEEEEEEE STR r2, [ap] LDR ro, – 0XEEAB123A ;dummy data BL Count MOV 3,rl B Parkilere RegisterValue0 Current OF FAB123A 0x00000013 :set up dumay x2 R1 000000013 call routine : read result endless loop R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 (5P) 0x00000054 R14 (LR) 000000014 R15 (PC) 000000018 0 ParkHere NOP 0 count STMED sp!, 2,1x) MOV Nov saver and return on the stacik r1, #0x0 r2, #32 13 onescount Movs ro,r0 , ROR #1 ADDcs r1,r1, #1 SUBS r2, r2, 1 BNE Onescount 15 restore r2 and return Stack DCD o,o, o, 0,0 User/System Fast Interrupt Interrupt 20 Stack DCD 0,0,0,0,0 21 END Project E Registers Simulation Show transcribed image text LDR r0, 0x11AB003F dummy value for rl (11 ones) MOV r1,#0x0 MOV r2,#32 MOVS r0,r0, ROR #1 ADDCS r1,r1,#1 SUBS r2 , r2 , #1 BNE OnesCount ; clear ones counter ;use r2 as the loop counter i Repeat: rotate ro right set Ilags ;if carry set increment 1s counter ; decrement loop counter until all bits tested OnesCount If this was a subroutine Count, the code might be area test, cODE, readwrite ADR sp, Stackl LDR r2 , =0xFFFFFFFF STR r2, [sp] LDR r0, – 0xFFAB123A BL MOV r3,rl NOP NOP ;set up dummy r2 ; dummy data :call routine ; read result Count STMFD sp!, (r2,lr] MOV r1, #0x0 MOV r2,#4 Count ; save r2 and return on the stack onesCount MOVS r0,r0, ROR #1 ADDCS r1,r1,#1 SUBS r2 , r2 , #1 BNE OnesCount LDMFD sp!, (r2,pc) ; restore r2 and returr Stack Stackl DCD 0,0,0,0,0 DCD 0,0,0,0,0
    CAUsers AlanCore7 Desktop ForBrusselsMay2012Chap3Problems.uvproj – pVision4 File Edit iew Project Flash Debug Peripherals Tools SVCS Window Help Registers 3Chap3Problems.asm area test, CoDE, readwrite ADR p, Stackl LDR r2,=0xEEEEEEEE STR r2, [ap] LDR ro, – 0XEEAB123A ;dummy data BL Count MOV 3,rl B Parkilere RegisterValue0 Current OF FAB123A 0x00000013 :set up dumay x2 R1 000000013 call routine : read result endless loop R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 (5P) 0x00000054 R14 (LR) 000000014 R15 (PC) 000000018 0 ParkHere NOP 0 count STMED sp!, 2,1x) MOV Nov saver and return on the stacik r1, #0x0 r2, #32 13 onescount Movs ro,r0 , ROR #1 ADDcs r1,r1, #1 SUBS r2, r2, 1 BNE Onescount 15 restore r2 and return Stack DCD o,o, o, 0,0 User/System Fast Interrupt Interrupt 20 Stack DCD 0,0,0,0,0 21 END Project E Registers Simulation

    Expert Answer


    . . .


    view full answer
  • QUESTION : (Solved) : Write Arm Program Armsim Following Read Text File Called Inputtxt String Characters Upperc Q32561711 . . .

    Write an ARM program in ARMSim# that will do the following:​

    Read the text from a file called “input.txt” as a string ofcharacters
    Uppercase every consonant
    Replace all vowels with an asterisk (*)
    Output the new string from memory to a file called”output.txt”
    For example:
    “input.txt” contains “Blind love couldn’t win as the facts all camein. But I know I’ll again chase after wind. What have I got if nota thought?”
    “output.txt” should contain “BL*ND L*V* C**LDN’T W*N *S TH* F*CTS*LL CAME *N. B*T * KN*W *’LL *G**N CH*S* *FT*R W*ND. WH*T H*V* *G*T *F N*T * TH**GHT?”
    Meeting the above requirements is a bare minimum for theassignment. In order to get full credit, your program should:

    have appropriate comments
    check for errors
    have a readable output
    Please submit a single file called “project2.s” to theassignment.

    Expert Answer


    . . .


    view full answer