Question

In: Computer Science

Worksheet 3 – Object Oriented Code Analysis OBJECTIVE: Explore analyzing existing code. INSTRUCTIONS: Complete the questions...

Worksheet 3 – Object Oriented Code Analysis

OBJECTIVE: Explore analyzing existing code.

INSTRUCTIONS: Complete the questions and submit this document with your answers.

Problem:

Use the code provided in class for the game that we are updating to answer the following questions.


Object Oriented Analysis
Student Name:   Date:
Questions   Details & Rationale for Answer


(1 pt) Which class contains the main/start for the program?  


(2 pts) What are the classes in the game?  


(3 pts) Create a bulleted list of the Player class attributes & methods. Mark (A) for attribute and (M) for Method and provide a brief description of the purpose for the attribute and methods. Hence, What do the attributes describe and methods do?

  

(1 pt) List one example of encapsulation  

(1 pt) List one example of abstraction  

(1 pt) List one example of usage of an access modifier
  

(1 pt) Describe when to use the modifier “private static final”?  


code:

import java.awt.Color;
import java.awt.Container;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferStrategy;
import java.io.Serializable;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;

public class SpaceInvaders extends JFrame implements Serializable {
   private static final long serialVersionUID = 6037236323540109415L;
   public static final int WIDTH = 600;
   public static final int HEIGHT = 600;
   BufferStrategy strategy;
   Container c = getContentPane();
   static JTextArea names = new JTextArea(10, 50);
   static JList<String> userList;
  
   private static int direction = 1;
  
   private static final String TITLE = "Space Invaders";
  
   public SpaceInvaders() {
       super(TITLE);
       final JPanel startPanel = new JPanel();
       startPanel.setBackground(Color.BLACK);
       JButton start = new JButton("Start");
       JButton multiPlayer = new JButton("Multiplayer");
       JButton exit = new JButton("Exit");
       startPanel.add(start);
       startPanel.add(multiPlayer);
       startPanel.add(exit);
       this.add(startPanel);
      
       ImageIcon pic = new ImageIcon("Resources\\Enemy.jpg");
       Image img = pic.getImage();
       setVisible(true);
       setSize(WIDTH, HEIGHT);
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setLocationRelativeTo(null);
       setResizable(false);
       setIgnoreRepaint(true);
       createBufferStrategy(2);
      
       start.addActionListener(new ActionListener() {
          
           @Override
           public void actionPerformed(ActionEvent e) {
               c.removeAll();
               JFrame frame = SpaceInvaders.this;
               c.add(GameCanvas.getGameCanvas(false));
               GameCanvas.getGameCanvas(false).grabFocus();
               frame.setContentPane(c);
               frame.repaint();
           }
       });
      
       multiPlayer.addActionListener(new ActionListener() {
       @Override
       public void actionPerformed(ActionEvent e) {
           c.removeAll();
           JFrame frame = SpaceInvaders.this;
           c.add(multiplayer());
           GameCanvas.getGameCanvas(true);
           multiplayer().grabFocus();
           frame.setContentPane(c);
           frame.repaint();
       }
       });
      
       exit.addActionListener(new ActionListener() {
          
           @Override
           public void actionPerformed(ActionEvent e) {
               System.exit(0);
           }
       });
      
       strategy = getBufferStrategy();
       strategy.show();
      
       setIconImage(img);
   }
  
   public static void main(String[] args) {
       SwingUtilities.invokeLater(new Runnable() {
          
           @Override
           public void run() {
               new SpaceInvaders();
           }
       });
   }
  
   public static int getDirection() {
       return direction;
   }
  
   public static void setDirection(int direction) {
       SpaceInvaders.direction = direction;
   }

public JPanel multiplayer() {
   JPanel panel = new JPanel();
   names.setEditable(false);
   panel.setBackground(Color.BLACK);
  
   userList = new JList<String>();
    userList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane theList = new JScrollPane(userList);
   userList.setListData(GameCanvas.listVector);
    names.add(userList);
    names.add(theList);
  
   panel.add(names);
  
   this.add(panel);
   return panel;
}
}

Solutions

Expert Solution

(1 pt) Which class contains the main/start for the program?  
=> class SpaceInvaders 

(2 pts) What are the classes in the game?  
=> class SpaceInvaders 

(3 pts) Create a bulleted list of the Player class attributes & methods. Mark (A) for attribute and (M) for Method and provide a brief description of the purpose for the attribute and methods. Hence, What do the attributes describe and methods do?
=> there is no player class in the given code.
  
  
(1 pt) List one example of encapsulation  
=> private static int direction = 1;
This variable can only be used and changed inside the class, Hence it is encapsulated.

(1 pt) List one example of abstraction  
=> frame.repaint();
This method is defined indeed in JFrame class, we do not know what exactly is written in JFrame class for this method, but with abstraction, we know that calling this method will re-draw everything on canvas.

(1 pt) List one example of usage of an access modifier
=>  public SpaceInvaders() {
Here public means that the SpaceInvaders constructor can be publically accessed from anywhere.

(1 pt) Describe when to use the modifier “private static final”?  
=> When the value is supposed to be used only inside the current class, and should never be changed.

**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

Explain Basic Characteristics of Object Oriented System Analysis & Design.
Explain Basic Characteristics of Object Oriented System Analysis & Design.
PART II — WORKSHEET COMPLETION Instructions: Complete the partial worksheet presented below, inserting additional labels as...
PART II — WORKSHEET COMPLETION Instructions: Complete the partial worksheet presented below, inserting additional labels as needed AUBREY SERVICES AGENCY Partial Worksheet For the Month Ended April 30, 2012 Account Titles Adjusted Trial Balance Income Statement Balance Sheet Dr. Cr. Dr. Cr. Dr. Cr. Cash      6,500.00 Accounts Receivable      2,000.00 Supplies      3,075.00 Prepaid Insurance      2,000.00 Prepaid Rent         500.00 Equipment    35,000.00 Accum. Depreciation      4,000.00 Notes Payable    14,000.00 Account Payable    12,000.00 Unearned Service Revenue      2,000.00 Salaries and Wages Payable      1,300.00 Interest Payable           50.00...
In this program, you are modifying given code so that the class is object-oriented. 2. Write...
In this program, you are modifying given code so that the class is object-oriented. 2. Write a Java class called CityDistancesOO in a class file called CityDistancesOO.java.    3. Your class will still make use of two text files. a. The first text file contains the names of cities with the first line of the file specifying how many city names are contained within the file.    b. The second text file contains the distances between the cities in the...
what is the essence of the object oriented analysis and design approach with UML diagramming tools
what is the essence of the object oriented analysis and design approach with UML diagramming tools
Please carefully review the code to fill in after the given instructions and complete the code...
Please carefully review the code to fill in after the given instructions and complete the code for me. Thank you in advance. In this problem, we will implement a simple dictionary of common words in the English language, represented as an array of words paired with their lengths. You will need to implement each of the below methods in the Dictionary class. In this problem, the first line of input represents the method to call. It will be one of...
POS-301: Analyzing Arizona Tax Worksheet Complete all five parts of the worksheet. Part One: Income Tax...
POS-301: Analyzing Arizona Tax Worksheet Complete all five parts of the worksheet. Part One: Income Tax Which branch of government Determines the Amount of Tax? Services the Tax is Applied Towards Federal Tax State Tax Social Security Tax Medicare Tax Other (Please specify) Part Two: Arizona Sales Tax 2. Who determines the amount of each tax? 3. Where does revenue from this tax go? What does it fund? Part Three: Arizona Utility Tax 2. Who determines the amount of each...
Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
C++ Please complete based on the code below. Declare another stack object to the code in...
C++ Please complete based on the code below. Declare another stack object to the code in main(). Add a stack operator called CopyStack to the Stack class which, when executed, copies the contents of the first stack into the second stack. Modify your menu so that this option is available. The menu should also allow the second stack to be printed, pushed, popped, and so forth, just like with the first stack. #include using namespace std; #define MAXSize 10 class...
What are CRC cards and use-case scenarios used for in object-oriented analysis and design?
What are CRC cards and use-case scenarios used for in object-oriented analysis and design?
There are many methodologies for developing information systems. Structured analysis, object-oriented analysis, agile methods, joint application...
There are many methodologies for developing information systems. Structured analysis, object-oriented analysis, agile methods, joint application development, and rapid application development are some of the methods. Research to find other development methods that are available. Describe your findings. Which method do you think is the best? Why do you think the method you chose is the best method for developing information systems? You should explain your reasoning for your point of view.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT