QuestionAnswered step-by-step// part 1 no half work. need accurate answers only 1. Use java…//part 1no half work.need accurate answers only1. text(a) One of the algorithms that you implement inside asmartcard requires a stack (LIFO) for storing datarecords. Assume that each record is a f… Show moreUse java Eclipse and update all your codQuestion 1Here is the code from last week’s lab, which creates a small GUI that can be used to draw a sequence of red lines. This code follows the Model-View-Controller design pattern:public interface ModelListener {public void update();}import java.awt.Point;import java.util.ArrayList;public class Model {private ArrayList points;private ArrayList listeners;public Model() {points = new ArrayList();listeners = new ArrayList();}public void addListener(ModelListener l) {listeners.add(l);}public ArrayList getPoints() {return points;}public void addPoint(Point p) {points.add(p);notifyListeners(); // points changed so notify the listeners.}public void clearAllPoints() {points.clear();notifyListeners(); // points changed so notify the listeners.}public void deleteLastPoint() {if(points.size() > 0) {points.remove(points.size() – 1);notifyListeners(); // points changed so notify the listeners.}}private void notifyListeners() {for(ModelListener l: listeners) {l.update(); // Tell the listener that something changed.}}public int numberOfPoints() {return points.size();}public static void testModel() {Model m = new Model();m.addListener(new ModelListener() {@Overridepublic void update() {System.out.println(true ” (listener)”);}});System.out.println(m.getPoints() == m.points);Point p1 = new Point(1, 2);Point p2 = new Point(3, 4);m.addPoint(p1); // Listener called.m.addPoint(p2); // Listener called.System.out.println(m.numberOfPoints() == 2);System.out.println(m.points.get(0) == p1);System.out.println(m.points.get(1) == p2);m.deleteLastPoint(); // Listener called.System.out.println(m.numberOfPoints() == 1);System.out.println(m.points.get(0) == p1);m.clearAllPoints(); // Listener called.System.out.println(m.numberOfPoints() == 0);m.notifyListeners(); // Listener called.}}public class Controller {protected Model m;public Controller(Model m) {this.m = m;}}import java.awt.Point;public class ControllerClicks extends Controller {public ControllerClicks(Model m) {super(m);}public void mouseClicked(Point p) {m.addPoint(p);}public void resetClicked() {m.clearAllPoints();}public void undoClicked() {m.deleteLastPoint();}}import javax.swing.JFrame;public abstract class View extends JFrame implements ModelListener {protected Model m;protected T c;public View(Model m, T c) {this.m = m;this.c = c;m.addListener(this);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}@Overridepublic abstract void update();}import java.awt.Color;import java.awt.Graphics;import java.awt.Point;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.util.ArrayList;import javax.swing.JPanel;public class MyPanel extends JPanel {private Model m;private ControllerClicks c;public MyPanel(Model m, ControllerClicks c) {this.m = m;this.c = c;this.addMouseListener(new MouseAdapter() {@Overridepublic void mouseClicked(MouseEvent e) {if(e.getButton() == MouseEvent.BUTTON1) {c.mouseClicked(e.getPoint());}}});}@Overrideprotected void paintComponent(Graphics g) {super.paintComponent(g);ArrayList points = m.getPoints();g.setColor(Color.RED);if(points.size() == 1) {Point p = points.get(0);g.drawRect((int)p.getX(), (int)p.getY(), 1, 1);} else {for(int i = 1; i < points.size(); i) {Point start = points.get(i - 1);Point end = points.get(i);g.drawLine((int)start.getX(), (int)start.getY(),(int)end.getX(), (int)end.getY());}}}}import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JPanel;public class MyFrame extends View {public MyFrame(Model m, ControllerClicks c) {super(m, c);this.setTitle(“MyFrame Title”);this.setSize(400, 300);this.setLocationRelativeTo(null);this.setLayout(new BorderLayout());MyPanel centerPanel = new MyPanel(m, c);this.add(centerPanel, BorderLayout.CENTER);JPanel topPanel = new JPanel();this.add(topPanel, BorderLayout.PAGE_START);topPanel.setLayout(new FlowLayout(FlowLayout.CENTER));JButton resetButton = new JButton(“Reset”);resetButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {c.resetClicked();}});topPanel.add(resetButton);JButton undoButton = new JButton(“Undo”);undoButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {c.undoClicked();}});topPanel.add(undoButton);this.setVisible(true);}@Overridepublic void update() {repaint(); // Makes Swing call MyPanel’s paintComponent method.}}import javax.swing.JLabel;public class ViewNumber extends View {private JLabel label;public ViewNumber(Model m, Controller c) {super(m, c);this.setTitle(“View Number”);this.setSize(150, 150);label = new JLabel();update(); // Initialize the label using the model.this.add(label);this.setVisible(true);}@Overridepublic void update() {label.setText(“Number of points is: ” m.numberOfPoints());}}public class Test {public static void main(String[] args) {Model.testModel();}}public class Start {public static void main(String[] args) {javax.swing.SwingUtilities.invokeLater(new Runnable() {@Overridepublic void run() {Model m = new Model();ControllerClicks c1 = new ControllerClicks(m);MyFrame v1 = new MyFrame(m, c1);Controller c2 = new Controller(m);ViewNumber v2 = new ViewNumber(m, c2);}});}}You can use the Test class to run all the tests for the software and you can use the Start class to run the software itself. Run this code and check that it works correctly.Add to the Model class a new method called savaData that saves into a text file called “points.txt” the integer coordinates x and y of each point in the arraylist of points. Also modify the constructor of the Model class to read the integer coordinates of all the points from the same text file, if it exists, and put them into the arraylist of points (if the file does not exist then the arraylist of points should remain empty).Add to the Controller superclass a protected shutdown method that:? calls the saveData method of the model;? manually terminates the program using System.exit(0).Then modify the View superclass to:? hide the frame when the user clicks on the “close” button;? add a “window closing” event handler (use an anonymous window adapter) that calls the controller’s shutdown method.Use the Test class to run all the tests for the software and check that all the tests still work.Use the Start class to run the software and check that closing the software correctly saves all the point coordinates in the file “points.txt” (you can find the file in the folder for your current project). Run the software again and check that all the points from the previous run are correctly displayed.Question 2Instead of using a text file to save all the point coordinates one by one, change the savaData method and the constructor of the Model class to use object serialization and a binary file called “points.bin” to write / read the whole arraylist of points to / from the file in one operation.Use the Test class to run all the tests for the software and check that all the tests still work.Use the Start class to run the software and check that closing the software correctly saves the arraylist of points in the file “points.bin” (you can find the file in the folder for your current project but it is a binary file so you will not be able to read its content). Run the software again and check that all the points from the previous run are correctly displayed.part 11.Why is a packet switching network more efficient than circuit switching network?Compare space-division and time-division switches.12.Describe datagram network of packet switching network?How does out of order manage in packet switching network?Why does circuit switching network call a connection less networks?How does packet move in datagram network?Compare the delays between datagram network and circuit switching network?13.Compare and contrast the two major categories of circuit switches. List four major components of a packet switch and their functions. textElectromagnetic Radiation -Prelab Name: Date: Lab day &time: Question: What are the basic properties of electromagneticradiation? Part P – 1: Light is a part of our everyday lif… Show moreComputer ScienceEngineering & TechnologyMYSQLCS 1050Share Question

Order your essay today and save 20% with the discount code ESSAYHELP