Skip to content

Instantly share code, notes, and snippets.

@micylt
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micylt/12277a91661992823e47 to your computer and use it in GitHub Desktop.
Save micylt/12277a91661992823e47 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Assignment_Four {
public static double balance = 1500.00;
public static double largest = 0.0;
public static double smallest = 10000.00; // should this be changed to 1500?
public static void main(String[] args) {
displayTransactions();
transactions();
}
public static void displayTransactions(){
System.out.println("The transactions types are as follows:");
System.out.println("A adding an amount to the account.");
System.out.println("S substracting an amount form the account.");
System.out.println("B getting the current balance of the account.");
System.out.println("M reporting the month end details of the account.");
System.out.println();
}
public static void transactions() {
Scanner scan = new Scanner(System.in);
for (int i = 0; i < 4; i++) {
System.out.print("Transaction type? ");
String type = scan.next();
if (type.equalsIgnoreCase("A") || type.equalsIgnoreCase("S")) {
System.out.print("Amount? ");
double amount = scan.nextDouble();
if (type.equalsIgnoreCase("A")) {
add(amount);
} else {
subtract(amount);
}
System.out.println("Current Balance: " + getBalance());
} else if (type.equalsIgnoreCase("B")) {
System.out.println("Current Balance: " + getBalance());
} else {
monthlyReport();
}
}
}
public static void add(double amount) {
balance += amount;
if (balance > largest) {
largest = balance;
}
}
public static void subtract(double amount) {
balance -= amount;
if (balance < smallest) {
smallest = balance;
}
}
public static double getBalance() {
return balance;
}
public static void monthlyReport() {
System.out.println("Monthly Report: ");
System.out.println("Smallest Balance: " + smallest);
System.out.println("Largest Balance: " + largest);
System.out.println("Final Balance: " + balance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment