Created
September 28, 2017 03:25
-
-
Save dzt/5268447f2614e32bba8a3682eee3cf70 to your computer and use it in GitHub Desktop.
Chp3 Finale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allows you to manage your BankAccount information and modify it by adding and withdrawing from the account. | |
* @author Peter Soboyejo | |
* @version 1.0 | |
* @since September 27, 2017 | |
*/ | |
public class BankAccount | |
{ | |
private double balance; | |
private double fee = 0.00; | |
private int editCount = 0; | |
private int freeEdits = 3; | |
/** | |
* Constructs the BankAccount Class | |
*/ | |
public BankAccount() | |
{ | |
balance = 0; | |
} | |
/** | |
* Deposits a specific amount of money to the account | |
* @param depositAmount Amount of money to deposit. | |
*/ | |
public void deposit(double depositAmount) { | |
balance += depositAmount - fee; | |
editCount++; | |
} | |
/** | |
* Fetches the current balance of the bank account. | |
* @return Current Balance in the Bank Account. | |
*/ | |
public double getBalance() { | |
return balance; | |
} | |
/** | |
* | |
* @param withdrawAmount Amount of money you want to withdraw from the account. | |
* @return Returns the Withdrawl amount | |
*/ | |
public double withdraw(double withdrawAmount) | |
{ | |
if(withdrawAmount > balance) return 0; | |
balance -= withdrawAmount - fee; | |
editCount++; | |
return withdrawAmount; | |
} | |
/** | |
* | |
* @param rate Rate of Interest (Percentage) | |
* @return Current Balance of the Bank Account | |
*/ | |
public double addInterest(double rate){ | |
balance = (balance*rate) + balance; | |
return balance; | |
} | |
/** | |
* Sets a fee for every deposit and withdrawal. | |
* @param fee Set fee for deposits and withdrawals. | |
*/ | |
public void setFee(double fee) { | |
this.fee = fee; | |
} | |
/** | |
* Deducts the monthly charge and resets transaction count. | |
*/ | |
public void deductMonthlyCharge() { | |
double summary = (editCount - freeEdits) * fee; | |
balance = balance - summary; | |
editCount = 0; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allows you to calculate car fuel economy. | |
* @author Peter Soboyejo | |
* @version 1.0 | |
* @since September 27, 2017 | |
*/ | |
public class Car { | |
private double mpg, fuel; | |
/** | |
* Constructs the Car Class | |
* @param mpg Fuel Economy | |
*/ | |
public Car(double mpg) { | |
this.mpg = mpg; | |
this.fuel = 0; | |
} | |
/** | |
* Adds Gas (Gallons) | |
* @param amount Amount of Gallons you want to add. | |
*/ | |
public void addGas(double amount) { | |
this.fuel += amount; | |
} | |
/** | |
* | |
* @param distance Distance being traveled during drive. | |
*/ | |
public void drive(double distance) { | |
this.fuel -= distance / mpg; | |
} | |
/** | |
* Returns the amount of Gas in the tank (gallons) | |
* @return Gas In Tank (Gallons) | |
*/ | |
public double getGasInTank() { | |
return fuel; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allows you to manage an Employee and get salary data. | |
* @author Peter Soboyejo | |
* @version 1.0 | |
* @since September 27, 2017 | |
*/ | |
public class Employee { | |
private String name; | |
private double salary; | |
/** | |
* Consstructs the Employee Class | |
* @param employeeName Designated name of the Employee | |
* @param currentSalary Initial Salary Value | |
*/ | |
public Employee(String employeeName, double currentSalary) { | |
name = employeeName; | |
salary = currentSalary; | |
} | |
/** | |
* Fetches for the name of the Employee | |
* @return Employee's Name | |
*/ | |
public String getName() { | |
return name; | |
} | |
/** | |
* Fetchess for the Employee's salary amount. | |
* @return Salary Amount | |
*/ | |
public double getSalary() { | |
return salary; | |
} | |
/** | |
* Raises the salary of an Employee by a specific percentage. | |
* @param byPercent The percentage you want to raise the salary too. | |
*/ | |
public void raisesSalary(double byPercent) { | |
salary *= 1+(byPercent*.01); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* OOP Alternative to the traditional Hello, World Program intended for BlueJ | |
* @author Peter Soboyejo | |
* @version 1.0 | |
* @since September 27, 2017 | |
*/ | |
public class Greeter { | |
private String name; | |
/** | |
* Constructs the Greeter Class | |
* @param name Designated Name | |
*/ | |
public Greeter(String name) { | |
this.name = name; | |
} | |
/** | |
* Formats greeting with name. | |
* @return Formatted String with name and greeting. | |
*/ | |
public String sayHello() | |
{ | |
return String.format("Hello, %s", name); | |
} | |
/** | |
* Formats goodbye method with name. | |
* @return Formatted String with name and goodbye message. | |
*/ | |
public String sayGoodbye() { | |
return String.format("Goodbye, %s", name); | |
} | |
/** | |
* Formats refusal message with name. | |
* @return Formatted String with name and refusal message. | |
*/ | |
public String refuseHelp() { | |
return String.format("I am sorry, %s, I am afraid I can't do that.", name); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allows you to manage specific Product data with pricing information. | |
* @author Peter Soboyejo | |
* @version 1.0 | |
* @since September 27, 2017 | |
*/ | |
public class Product { | |
private double price; | |
private String name; | |
/** | |
* Constructor of the Product Class | |
* @param name Name of the Product | |
* @param price Price of the Product | |
*/ | |
public Product(String name, double price) { | |
this.name = name; | |
this.price = price; | |
} | |
/** | |
* Fetches current price of the product. | |
* @return Current Price of the Product | |
*/ | |
public double getPrice() { | |
return price; | |
} | |
/** | |
* Gets current name of the product. | |
* @return Name of the Product. | |
*/ | |
public String getName() { | |
return name; | |
} | |
/** | |
* Reduces the Price of the Product | |
* @param amount Amount of money to be reduced from the current price of the product | |
*/ | |
public void reducePrice(double amount) { | |
price-=amount; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allows you to manage your Savings Account information and modify it by adding and withdrawing from the account with | |
* specific features catered to savings. | |
* @author Peter Soboyejo | |
* @version 1.0 | |
* @since September 27, 2017 | |
*/ | |
public class SavingsAccount extends BankAccount { | |
private double rate = 0; | |
/** | |
* Constructs the SavingsAccount Class | |
* @param balance Initial Balance | |
* @param rate Initial Rate of Interest | |
*/ | |
public SavingsAccount(double balance, double rate) { | |
deposit(balance); | |
this.rate = rate; | |
} | |
/** | |
* Adds interest to the Savings Account with the interest rate set in the constructor. | |
*/ | |
public void addInterest() { | |
deposit(getBalance() * rate / 100); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allows you manage Student Quiz Scores and access specific analytics. | |
* @author Peter Soboyejo | |
* @version 1.0 | |
* @since September 27, 2017 | |
*/ | |
public class Student { | |
private String name; | |
private double totalQuizScore; | |
private int numberOfQuizzes; | |
/** | |
* Constructor for the Student Class | |
* @param name Designated name assigned to the Student | |
*/ | |
public Student(String name) { | |
this.name = name; | |
this.totalQuizScore = 0; | |
this.numberOfQuizzes = 0; | |
} | |
/** | |
* Fetches the current name of the Student assigned to the class | |
* @return Name of the Student | |
*/ | |
public String getName() { | |
return name; | |
} | |
/** | |
* Adds a Quiz Score | |
* @param score Grade of the Quiz | |
*/ | |
public void addQuiz(int score) { | |
totalQuizScore+=score; | |
numberOfQuizzes++; | |
} | |
/** | |
* Gets the total points added | |
* @return Total Points of Quizzess | |
*/ | |
public double getTotalScore() { | |
return totalQuizScore; | |
} | |
/** | |
* Gets the Average Score of Quiz Grades from the Student | |
* @return Average Score of Quiz Grades from the Student | |
*/ | |
public double getAverageScore() { | |
return (totalQuizScore/numberOfQuizzes); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment