Hacks
5.1-5.3 Hacks
POPCORN HACKS: 0.2
Create a simple To-Do List that utilizes the following (0.8):
-
Private and Public Declaration
-
Constructor
-
Mutable Array containing To-Do List Items
Make sure to add descriptive comments that are describing your code!
5.4-5.8 Hacks
POPCORN HACKS: 0.2
Make simple banking application. The application should be able to handle new customer bank account requests, processing deposits and withdrawals, and maintaining accurate records of transactions and balances. The application should also track the bank’s total supply of money. Your code should utilize the following concepts(0.8):
Scope and Access: Private and public modifiers used in classes.
Method Decomposition: Each class has its own responsibility; methods are tasked with single operations.
Non-Void Methods: Methods like getBalance(), getAccountNumber(), and getTotalBankDeposits().
Void Methods: Methods like deposit(), withdraw(), and processTransaction().
Formal Parameters: Used in methods throughout the classes.
Reference vs. Primitive Parameters: Primitive types for account numbers, balances, etc., and references for account objects.
public class Customer{
private String name;
private int age;
private int bankNumber;
private double balance;
public Customer(String name, int age, int bankNumber, double balance){
this.name = name;
this.age = age;
this.bankNumber = bankNumber;
this.balance = balance;
}
public void changeMoney(double amount){
this.balance = this.balance + amount;
return;
}
public String getName(){
return this.name;
}
public int getAge(){
return this.age;
}
public int getBankNumber(){
return this.bankNumber;
}
public double getBalance(){
return this.balance;
}
}
public class Record{
private double amount;
private String accountName;
private String type;
private int bankNumber;
public Record(double amount, String accountName, String type, int bankNumber){
this.amount = amount;
this.accountName = accountName;
this.type = type;
this.bankNumber = bankNumber;
}
public double getAmount(){
return this.amount;
}
public int getBankNumber(){
return this.bankNumber;
}
public String getName(){
return this.accountName;
}
public String getType(){
return this.type;
}
}
public class Bank{
private ArrayList<Customer> customers = new ArrayList<Customer>();
private ArrayList<Record> records = new ArrayList<Record>();
public Bank(){
}
public Bank(ArrayList<Customer> customers){
this.customers = customers;
}
public void newCustomer(Customer customer){
this.customers.add(customer);
}
public void deposit(Customer customer, double amount){
customer.changeMoney(amount);
this.records.add(new Record(amount, customer.getName(), "Deposit", customer.getBankNumber()));
return;
}
public void withdraw(Customer customer, double amount){
customer.changeMoney(-amount);
this.records.add(new Record(amount, customer.getName(), "Withdrawal", customer.getBankNumber()));
return;
}
public ArrayList<Customer> getCustomers(){
return this.customers;
}
public ArrayList<Record> getRecords(){
return this.records;
}
public static void main(String[] args){
Customer customer1 = new Customer("Rohin", 10, 1, .50);
Customer customer2 = new Customer("Vaardan", 17, 2, 50);
Customer customer3 = new Customer("Vishnu", 15, 3, 500);
Customer customer4 = new Customer("Akshat", 20, 4, 50000);
Bank bank = new Bank();
bank.newCustomer(customer1);
bank.newCustomer(customer2);
bank.newCustomer(customer3);
bank.newCustomer(customer4);
for (Customer customer : bank.getCustomers()){
System.out.println("Name: " + customer.getName() + ", Age: " + customer.getAge() + ", Balance: " + customer.getBalance());
}
System.out.println();
bank.deposit(customer1, 100.0);
bank.withdraw(customer4, 3600.0);
for (Customer customer : bank.getCustomers()){
System.out.println("Name: " + customer.getName() + ", Age: " + customer.getAge() + ", Balance: " + customer.getBalance());
}
System.out.println();
System.out.println("Records:");
for (Record record : bank.getRecords()){
System.out.println("Name: " + record.getName() + ", Amount: " + record.getAmount() + ", Type: " + record.getType() + ", Bank Number: " + record.getBankNumber());
}
}
}
Bank.main(null)
// these hacks took way too long bruh
Name: Rohin, Age: 10, Balance: 0.5
Name: Vaardan, Age: 17, Balance: 50.0
Name: Vishnu, Age: 15, Balance: 500.0
Name: Akshat, Age: 20, Balance: 50000.0
Name: Rohin, Age: 10, Balance: 100.5
Name: Vaardan, Age: 17, Balance: 50.0
Name: Vishnu, Age: 15, Balance: 500.0
Name: Akshat, Age: 20, Balance: 46400.0
Records:
Name: Rohin, Amount: 100.0, Type: Deposit, Bank Number: 1
Name: Akshat, Amount: 3600.0, Type: Withdrawal, Bank Number: 4
5.9-5.10 Hacks
POPCORN HACKS: 0.2
Write a two sentence reflection on the social and ethical implications of programming. (0.8)
public class Task{
public String deadline;
public String taskName;
public double timeEstimate;
public Task(String deadline, String taskName, double timeEstimate){
this.deadline = deadline;
this.taskName = taskName;
this.timeEstimate = timeEstimate;
}
}
public class ToDo{
private ArrayList<Task> Tasks = new ArrayList<>();
public ToDo(){
Task task = new Task("10/10/2024", "AP Stats Homework", 0.5);
Tasks.add(task);
return;
}
public void newTask(Task task){
Tasks.add(task);
return;
}
public ArrayList<Task> getTasks(){
return this.Tasks;
}
public static void main(String[] args){
ToDo toDo = new ToDo();
Task physics = new Task("12/10/2024", "AP Physics Homework", 100);
toDo.newTask(physics);
for (Task task : toDo.getTasks()){
System.out.println("Task Name: " + task.taskName + "\nDeadline: " + task.deadline + "\nEstimated Time: " + task.timeEstimate + " hours \n");
}
}
}
ToDo.main(null)
Task Name: AP Stats Homework
Deadline: 10/10/2024
Estimated Time: 0.5 hours
Task Name: AP Physics Homework
Deadline: 12/10/2024
Estimated Time: 100.0 hours
There are many negative social and ethical implications of programming, with many of the major issues coming down to data privacy. Data can be very useful, possibly even necessary, for certain projects to run effectively, but it’s important to remain ethical in our use of private user data and to comply with laws.