java DDI Osrc main java > ControlPanel.java 129 v 130 131 132 133 134 135 ✓ 136 137 138 v 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161, 162 163 164 165 166 167 168 169 170 } } private void execute Instruction ( Instruction instruction) { String opcode= instruction.getOpcode(); int[] args = instruction.getArgs(); switch (opcode) { case "load": } for (Instruction instruction instructions) { if (!miniMac.isRunning()) break; executeInstruction (instruction); } }$$ } miniMac.load(args[0], args[1]); break; case "halt": miniMac.halt (); $ break; case "add": miniMac.add(args[0], args[1], args[2]); break; case "mul": miniMac.mul(args[0], args[1], args[2]); break; default: // Placeholder for other operations break; private void updateMemoryView() { DefaultListModel memoryModel = new DefaultListModel(); Integer [] memory - miniMac.getMemory(); for (int i = 0; i< memory.length; i++) { memoryModel.addElement("Memory[" + i + "]: " + memory[i]); } updateMemoryView(); memoryView.setModel (memoryModel); public static void main(String[] args) { SwingUtilities.invokeLater (Control Panel::new); Format Hell

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

import javax.swing.*;
import java.awt.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

class MiniMac {
    private Integer[] memory;
    private boolean running;

    public MiniMac() {
        memory = new Integer[32];
        Arrays.fill(memory, 0);
        running = true;
    }

    public void load(int location, int value) {
        memory[location] = value;
    }

    public void halt() {
        running = false;
    }

    public void add(int src1, int src2, int dest) {
        memory[dest] = memory[src1] + memory[src2];
    }

    public void mul(int src1, int src2, int dest) {
        memory[dest] = memory[src1] * memory[src2];
    }

    public Integer[] getMemory() {
        return memory;
    }

    public boolean isRunning() {
        return running;
    }
}

class Instruction {
    private String opcode;
    private int[] args;

    public Instruction(String opcode, int[] args) {
        this.opcode = opcode;
        this.args = args;
    }

    public String getOpcode() {
        return opcode;
    }

    public int[] getArgs() {
        return args;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(opcode);
        for (int arg : args) {
            sb.append(" ").append(arg);
        }
        return sb.toString();
    }
}

class MiniMacParser {
    public static List<Instruction> parse(String program) {
        List<Instruction> instructions = new ArrayList<>();
        String[] lines = program.split("\n");
        for (String line : lines) {
            instructions.add(parseInstruction(line.trim()));
        }
        return instructions;
    }

    private static Instruction parseInstruction(String line) {
        String[] tokens = line.split("\\s+");
        String opcode = tokens[0];
        int[] args = new int[tokens.length - 1];
        for (int i = 1; i < tokens.length; i++) {
            args[i - 1] = Integer.parseInt(tokens[i]);
        }
        return new Instruction(opcode, args);
    }
}

public class ControlPanel extends JFrame {
    private MiniMac miniMac;
    private JList<String> memoryView;
    private JList<String> programView;

    public ControlPanel() {
        miniMac = new MiniMac();
        setupUI();
    }

    private void setupUI() {
        memoryView = new JList<>();
        programView = new JList<>();
        JButton loadProgramButton = new JButton("Load Program");
        loadProgramButton.addActionListener(e -> loadProgram());
        JPanel panel = new JPanel(new GridLayout(1, 2));
        panel.add(new JScrollPane(memoryView));
        panel.add(new JScrollPane(programView));
        add(panel, BorderLayout.CENTER);
        add(loadProgramButton, BorderLayout.SOUTH);
        setTitle("MiniMac Control Panel");
        setSize(600, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    private void loadProgram() {
        String program = "load 0 10\nload 1 20\nadd 0 1 2\nmul 0 1 3";
        List<Instruction> instructions = MiniMacParser.parse(program);
        DefaultListModel<String> programModel = new DefaultListModel<>();
        for (Instruction instruction : instructions) {
            programModel.addElement(instruction.toString());
        }
       programView.setModel(programModel);
        executeProgram(instructions);
    }

    private void executeProgram(List<Instruction> instructions) {
        for (Instruction instruction : instructions) {
            if (!miniMac.isRunning()) break;
            executeInstruction(instruction);
        }
    }

I paste the half code and the rest half i sent you in screenshot. Please check why the output i am getting "Hello World" PLease check where i am doing mistake and help me to fix 

Search
- Files Ⓒ
src
main
java
Control Panel.java
Packager files
target
pom.xml
→ Tools
Recent
All
CAI
Deployments
Authentication
Chat
Main.java
Control Panel.java X +
□src › □ main › java › Control Panel.java
129 v
130
131
132
133
134
135
136
V
137
138 v
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158 v
159
160
161
162
163
164
165
166
167 v
168
169
170 }
171
}
}
private void executeInstruction ( Instruction instruction) {
String opcode instruction.getOpcode();
instruction.getArgs();
int[] args
switch (opcode) {
case "load":
for (Instruction instruction: instructions) {
if (!miniMac.isRunning()) break;
executeInstruction (instruction);
}
}
}
}$$
=
}
miniMac.load(args[0], args[1]);
=
break;
case "halt":
miniMac.halt();$
break;
case "add":
miniMac.add(args[0], args[1], args[2]);
break;
case "mul":
miniMac.mul(args[0], args[1], args[2]);
break;
default:
private void updateMemoryView() {
DefaultListModel<String> memoryModel = new DefaultListModel<>();
Integer [] memory miniMac.getMemory();
for (int i = 0; i < memory.length; i++) {
memoryModel.addElement("Memory[" + i + "]:
// Placeholder for other operations
break;
updateMemoryView();
memoryView.setModel (memoryModel );
public static void main(String[] args) {
SwingUtilities.invokeLater(Control Panel::new);
+ memory[i]);
Format
Console
Run
Hello world!
Shell
+
Transcribed Image Text:Search - Files Ⓒ src main java Control Panel.java Packager files target pom.xml → Tools Recent All CAI Deployments Authentication Chat Main.java Control Panel.java X + □src › □ main › java › Control Panel.java 129 v 130 131 132 133 134 135 136 V 137 138 v 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 v 159 160 161 162 163 164 165 166 167 v 168 169 170 } 171 } } private void executeInstruction ( Instruction instruction) { String opcode instruction.getOpcode(); instruction.getArgs(); int[] args switch (opcode) { case "load": for (Instruction instruction: instructions) { if (!miniMac.isRunning()) break; executeInstruction (instruction); } } } }$$ = } miniMac.load(args[0], args[1]); = break; case "halt": miniMac.halt();$ break; case "add": miniMac.add(args[0], args[1], args[2]); break; case "mul": miniMac.mul(args[0], args[1], args[2]); break; default: private void updateMemoryView() { DefaultListModel<String> memoryModel = new DefaultListModel<>(); Integer [] memory miniMac.getMemory(); for (int i = 0; i < memory.length; i++) { memoryModel.addElement("Memory[" + i + "]: // Placeholder for other operations break; updateMemoryView(); memoryView.setModel (memoryModel ); public static void main(String[] args) { SwingUtilities.invokeLater(Control Panel::new); + memory[i]); Format Console Run Hello world! Shell +
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Avoiding deadlock
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education