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...
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...
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
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...
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.
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
Objective of this Assignment: To conduct a regression and correlation analysis Instructions: The term paper involves...
Objective of this Assignment: To conduct a regression and correlation analysis Instructions: The term paper involves conducting a regression and correlation analysis on any topic of your choosing. The paper must be based on yearly data for any economic or business variable, for a period of at least 20 years (Note: the source of the data must be given. Data which is not properly documented as to source is unacceptable and paper will be graded F. Textbook examples are unacceptable)....
Objective of this Assignment:    To conduct a regression and correlation analysis Instructions: The term paper involves...
Objective of this Assignment:    To conduct a regression and correlation analysis Instructions: The term paper involves conducting a regression and correlation analysis on any topic of your choosing. The paper must be based on yearly data for any economic or business variable, for a period of at least 20 years (Note: the source of the data must be given. Data which is not properly documented as to source is unacceptable and paper will be graded F. Textbook examples are unacceptable)....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT