Question

In: Computer Science

Describe how you would develop object-oriented features of Java for the Quiz program developed in the...

Describe how you would develop object-oriented features of Java for the Quiz program developed in the Programming Assignments. In particular, describe how the program could use each of the following: class variables, instance variables, inheritance, polymorphism, abstract classes, "this", "super", interfaces, and event listeners.


Your Discussion should be at least 250 words in length, but not more than 750 words. Once you’ve completed your initial post, be sure to respond to the posts of at least 3 of your classmates.


Solutions

Expert Solution

class variables: Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block.Static variables can be accessed by calling with the class name  ClassName.VariableName.

instance variables: Instance variables are declared in a class, but outside a method, constructor or any block.Instance variables can be accessed directly by calling the variable name inside the class. However, within static methods (when instance variables are given accessibility), they should be called using the fully qualified name. ObjectReference.VariableName.

Example:

public class VariableExample{
   int myVariable;
   static int data = 50;
   
   public static void main(String args[]){
      VariableExample obj = new VariableExample();
      
      System.out.println("Value of instance variable: "+obj.myVariable);
      System.out.println("Value of static variable: "+VariableExample.data);
   }
}

Output:

Value of instance variable: 0
Value of static variable: 50

inheritance: An important feature of object-oriented programs is inheritance—the ability to create classes that share the attributes and methods of existing classes, but with more specific features. Inheritance is mainly used for code reusability.

polymorphism: Java Polymorphism is one of easy concept to understand. Polymorphism definition is that Poly means many and morphos means forms. It describes the feature of languages that allows the same word or symbol to be interpreted correctly in different situations based on the context. There are two types of Polymorphism available in Java. For example, in English, the verb “run” means different things if you use it with “a footrace,” a “business,” or “a computer.” You understand the meaning of “run” based on the other words used with it.

abstract classes: A class that is declared using “abstract” keyword is known as abstract class.

"this": In many object-oriented programming languages, this is a variable that is used in instance methods to refer to the object on which they are working.

"super":The super keyword refers to superclass objects. It is used to call superclass methods, and to access the superclass constructor. The most common use of the super keyword is to eliminate the confusion between superclasses and subclasses that have methods with the same name.

interfaces: An interface is a programming structure/syntax that allows the computer to enforce certain properties on an object.

event listeners:The Event listener represent the interfaces responsible to handle events. Java provides us various Event listener classes but we will discuss those which are more frequently used. Every method of an event listener method has a single argument as an object which is subclass of EventObject class


Related Solutions

Describe how you would develop object-oriented features of Java for the Quiz program developed in the...
Describe how you would develop object-oriented features of Java for the Quiz program developed in the Programming Assignments. In particular, describe how the program could use each of the following: class variables, instance variables, inheritance, polymorphism, abstract classes, "this", "super", interfaces, and event listeners.
PHP You will be using the object oriented features of PHP to design a music album...
PHP You will be using the object oriented features of PHP to design a music album processing page. First you will build a form page called addAlbum.php. This form will contain text fields for album title, artist, publisher (Sony, BMI, etc.) and genre. Add two more fields of your choice. You will post this form to the file process.php. If all the fields have values, we will create a new Album object and print the details of the object. You...
This program should be done in python. This must use the principles of object oriented program....
This program should be done in python. This must use the principles of object oriented program. Create one or more classes to play Four-in-a-Row (also called Connect Four) with a user. It’s similar to tic-tac-toe but the board is of size 7×6 and discs fall straight through so the legal moves are more stringent than tic-tac-toe. The state of the board should be printed to the terminal after each legal move. You can represent the different colored discs as X’s...
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...
Describe the types of hierarchy found in object-oriented systemdescriptions.
Describe the types of hierarchy found in object-oriented system descriptions.
OBJECT-ORIENTED JAVA The catch-or-declare requirement states that you have two choices: You can either catch the...
OBJECT-ORIENTED JAVA The catch-or-declare requirement states that you have two choices: You can either catch the exception or you can provide a throws clause. To which exceptions does the catch-or-declare requirement apply? Errors All Exceptions except RuntimeExceptions RuntimeExceptions All Throwable except Errors Flag this Question Question 21 pts Assume you have an array called numbers. It's elements are of type int and it was declared like this: int[] numbers = { 3, 6, 9, 12 }; Assume that you also...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used to hold the rectangle’s width....
Need a program in java that creates a random addition math quiz The program should ask...
Need a program in java that creates a random addition math quiz The program should ask the user to enter the following The smallest and largest positive numbers to be used when generating the questions - The total number of questions to be generated per quiz - The total number of the quiz's to create from then the program should generate a random math (Just addition) quiz from what the user entered
Object-Oriented Design and Patterns in Java (the 3rd Edition Chapter 5) - Create a directory named...
Object-Oriented Design and Patterns in Java (the 3rd Edition Chapter 5) - Create a directory named as the question number and save the required solutions in the directory. - Each problem comes with an expected tester name. In the directory for a given problem, including the tester and all java classes successfully run this tester. Exercise 5.2 ObserverTester.java - Improve Exercise 1 by making the graph view editable. Attach a mouse listener to the panel that paints the graph. When...
You have written a JAVA program that creates Shoe object with three instance variables. You will...
You have written a JAVA program that creates Shoe object with three instance variables. You will need to use the exception you created to go along with it. So far you have been using my driver classes. Now it is time for you to create your own driver class that will implement an ArrayList of Shoe objects. This assignment uses the Shoe.java and ShoeException.java to create the driver ShoeStore.Java You will display a menu as follows: Add shoes Print all...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT