OBJECT-ORIENTED PROGRAMMING Flashcards
Everything in OOP is associated with classes and objects, Describe the differences between Class and Object.
CLASS
A class is a template for
objects.
OBJECT
An object is a member or an
“instance” of a class.
CLASS
A class defines object properties including a valid range of values, and a default value.
OBJECT
An object has a state in which all of its properties have values you either explicitly define or that are defined by default settings.
CLASS
A class also describes object
behavior.
State TWO (2) object-oriented programming characteristic and explain the characteristics.
ABSTRACTION
* Process of taking away or removing characteristics from an object in order
to reduce it to a set of essential characteristics.
ENCAPSULATION (DATA HIDING)
* Binding or wrapping‐up of data and associated methods into a single unit.
The goal of the SDLC is to produce superior software that meets and all customer expectations and demands. List FIVE (5) stages of Software Cycle.
- Analysis
- Design
- Coding
- Testing
- Operation and Maintenance
Reserved words in Java serve as a code key. These words can’t be use anything else because they’re predefined. State FIVE (5) java reserved words.
- class
- boolean
- int
- double
- float
* public
* static
* void
* if
* else
```
public class Cinema
{
private String movieHall;
private String movieTitIe;
private double price;
private String modePayment; // QRPayment, Cash private String membership; //
definition of methods
}
~~~
A parameterized/normal constructor to initialize the object values.
public Cinema (String movieHall, String movieTitle, double price, String modePayment, Stringmembership) { movieHall = mH; movieTitle = mT; price = p; modePayment = mP; membership = m; }
```
public class Cinema
{
private String movieHall;
private String movieTitIe;
private double price;
private String modePayment; // QRPayment, Cash private String membership; //
definition of methods
}
~~~
A mutator and accessor methods for all data members.
Accessor (Getter)
~~~
public String getMovieHall()
{
return movieHall;
}
public String getMovieTitle()
{
return movieTitle;
}
public double getPrice()
{
return price;
}
public String getModePayment()
{
return modePayment;
}
public String getMembership()
{
return membership;
}
~~~
Mutator (Setters)
~~~
public void setMovieHall(String movieHall)
{
movieHall = mH;
}
public void setMovieTitle(String movieTitle)
{
movieTitle = mT;
}
public void setPrice(double price)
{
price = p;
}
public void setModePayment(String modePayment)
{
modePayment = mP;
}
public void setMembership(String membership)
{
membership = m;
}
~~~
The method calculateDiscount() to return the discount rate based
on the mode of payment and membership of every customer.
The table at Google Classroom ‘Exercise’ file.
public calculateDiscount() { double price; double discount; if (modePayment.equalsIgnoreCase("QR")) { if (membership.equalsIgnoreCase("True")) { discountRate = price*7/100; } else { discountRate = price*3/100; } } else if (modePayment.equalsIgnoreCase("Cash")) { if (membership.equalsIgnoreCase("True ")) { discountRate = price*10/100; } else { discountRate = price*5/100; } } return discountRate; } }
Write a program to ask user to input and store all information needed.
The table at Google Classroom ‘Exercise’ file.
main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Are you member? "); String membership = input.next(); System.out.println(“Please insert price"); double price = input.nextDouble(); String movieHall = scanner.nextLine(); System.out.println("QR or Cash"); String modePayment = input.next(); }
A printer method to display all the information.
The table at Google Classroom ‘Exercise’ file.
public static void Print() { System.out.println("Movie Hall: " + movieHall); System.out.println("Movie Title: " + movieTitle); System.out.println("Price: " + price); System.out.println("Mode of Payment: " + modePayment); System.out.println("Membership: " + membership); System.out.println("Discount Rate: " + (calculateDiscount() * 100) + "%"); }
Create an array of object hallCapacity that can store hundreds (150) data.
Hall [ ] hallCapacity = new Hall[150];
Java package for input-output program.
import java.io.*;
To open a file name** stock.txt**t for reading, totalstock.txt for writing, and printing process. (Include the class declaration).
import java.io.*; import java.util.*;
public class scoreboard { public static void main(String[] args) throws Exception { try{ BufferedReader fr = new BufferedReader (new FileReader("score.txt")); Bufferedwriter br = new Bufferedwriter (new FileWriter ("scoreout.txt")); Printwriter pr = new PrintWriter (br) ;
To close all file streams in used.
fr.close(); br.close();
To handle exception for file input-output processes.
catch (FileNotFoundException fnf) { System.out.println(fnf.getMessage()); } catch (EOFException eof) { System.out.println(eof.getMessage()); } catch (IOException io) { System.out.println(io.getMessage()); }
Write a program that will calculate the length of the array for element show below:
~~~
int [ ][ ] a = {
{1, 2, 3},
{4, 5, 6, 9},
{7}
}
~~~
public class ArrayLengthCalculator { public static void main(String[] args) { int [ ][ ] a = { {1, 2, 3}, {4, 5, 6, 9}, {7} }; int totalLength = 0; for (int i = 0; i < a.length; i++) { totalLength += a[i].length; } System.out.println("Total length of the array: " + totalLength); } }