zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcard
Study GuideStudy GuideQuestion BankQuestion Bank

How are classes used in designing a banking system?

Classes can represent entities like accounts, customers, and transactions, each with specific attributes and behaviors.

Flip to see [answer/question]
Flip to see [answer/question]
Revise later
SpaceTo flip
If confident

All Flashcards

How are classes used in designing a banking system?

Classes can represent entities like accounts, customers, and transactions, each with specific attributes and behaviors.

How are classes used in developing a game?

Classes can represent game objects like players, enemies, and items, each with their own properties and actions.

How are classes used in creating a graphical user interface (GUI)?

Classes can represent GUI components like buttons, text fields, and windows, each with specific properties and event handlers.

How are classes used in managing data in a database?

Classes can represent database tables and records, each with specific fields and methods for data manipulation.

How is encapsulation applied in real-world scenarios?

Protecting sensitive information in a user profile by making attributes private and providing controlled access through methods.

How are classes used in designing a library management system?

Classes can represent books, members, and librarians, each with specific attributes and behaviors related to borrowing and returning books.

How are classes used in developing an e-commerce platform?

Classes can represent products, customers, orders, and shopping carts, each with specific attributes and methods for managing products and processing orders.

How are classes used in creating a social media application?

Classes can represent users, posts, comments, and messages, each with specific attributes and methods for creating and sharing content.

How are classes used in managing student records in a school?

Classes can represent students, courses, teachers, and grades, each with specific attributes and methods for managing student information and academic performance.

How are classes used in designing a flight booking system?

Classes can represent flights, passengers, bookings, and airports, each with specific attributes and methods for managing flight schedules and booking reservations.

What are the differences between a constructor and a method?

Constructor: Initializes objects, has the same name as the class, no return type. | Method: Performs actions, can have any name, has a return type (or void).

What are the differences between public and private access modifiers?

Public: Accessible from anywhere. | Private: Accessible only within the class.

What are the differences between instance variables and local variables?

Instance variables: Declared within a class, outside any method, accessible by all methods in the class. | Local variables: Declared within a method, accessible only within that method.

What are the differences between getter and setter methods?

Getter: Accesses the value of an instance variable. | Setter: Modifies the value of an instance variable.

What are the differences between a class and an object?

Class: A blueprint or template. | Object: An instance of a class.

What are the differences between a default constructor and a parameterized constructor?

Default constructor: No parameters, provides default values. | Parameterized constructor: Takes parameters, allows custom initialization.

What are the differences between a method with a return type and a method with a void return type?

Return type: Returns a value of the specified type. | Void: Does not return any value.

What are the differences between a class header and a class body?

Class header: Specifies the class name and visibility. | Class body: Contains variable declarations and methods.

What are the differences between creating a new object and using an existing object?

Creating a new object: Allocates new memory and initializes the object. | Using an existing object: Operates on an object that has already been created.

What are the differences between calling a getter method and directly accessing a public instance variable?

Getter method: Provides controlled access and allows additional logic. | Public instance variable: Direct access, no control or additional logic.

Identify the error in the following code:

java
public class Square {
 private int side;
 public Square(int s) {
  side = s
 }
}

Missing semicolon after side = s.

What does the following code output?

java
public class Example {
 public static void main(String[] args) {
  Square mySquare = new Square(5);
  System.out.println(mySquare.getArea());
 }
}

class Square {
 private int side;
 public Square(int side) {
  this.side = side;
 }
 public int getArea() {
  return side * side;
 }
}

25

Complete the following code snippet to create a default constructor for the Rectangle class:

java
public class Rectangle {
 private int width;
 private int height;

 // Complete the code here

}
java
 public Rectangle() {
 width = 0;
 height = 0;
 }

Identify the error in the following code:

java
public class Circle {
 private double radius;

 public void Circle(double r) {
  radius = r;
 }
}

The constructor Circle should not have a void return type.

What does the following code output?

java
public class Test {
 public static void main(String[] args) {
  House myHouse = new House("123 Main St", 3);
  System.out.println(myHouse.getAddress());
 }
}

class House {
 private String address;
 private int rooms;
 public House(String address, int rooms) {
  this.address = address;
  this.rooms = rooms;
 }
 public String getAddress() {
  return address;
 }
}

123 Main St

Complete the following code snippet to create a getter method for the make attribute of the Car class:

java
public class Car {
 private String make;

 // Complete the code here

}
java
 public String getMake() {
 return make;
 }

What does the following code output?

java
public class Example {
 public static void main(String[] args) {
  Plant myPlant = new Plant("Rose", 1.5);
  System.out.println(myPlant.getHeight());
 }
}

class Plant {
 private String species;
 private double height;
 public Plant(String species, double height) {
  this.species = species;
  this.height = height;
 }
 public double getHeight() {
  return height;
 }
}

1.5

Identify the error in the following code:

java
public class Student {
 private String name;
 public Student(name) {
  this.name = name;
 }
}

Missing data type in the constructor parameter declaration. Should be public Student(String name).

What does the following code output?

java
public class Example {
 public static void main(String[] args) {
  Phone myPhone = new Phone("Apple", "iPhone 13", "Blue");
  myPhone.makeCall();
 }
}

class Phone {
 private String brand;
 private String model;
 private String color;
 public Phone(String brand, String model, String color) {
  this.brand = brand;
  this.model = model;
  this.color = color;
 }
 public void makeCall() {
  System.out.println("Calling...");
 }
}

Calling...

Complete the following code snippet to create a setter method for the rooms attribute of the House class:

java
public class House {
 private int rooms;

 // Complete the code here

}
java
 public void setRooms(int rooms) {
 this.rooms = rooms;
 }