Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package forni;
- import java.util.ArrayList;
- import java.util.Scanner;
- /**
- *
- * @author ihab
- */
- public class Forni {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Account a1 = new Account("ihab", 232, 545, new Address(3 , "street", "suburb", "city"));
- Account a2 = new Account("moey", 0, 545, new Address(3 , "street", "suburb", "city"));
- Account a3 = new Account("gary", 123, 545, new Address(3 , "street", "suburb", "city"));
- Account a4 = new Account("gary", 456, 545, new Address(3 , "street", "suburb", "city"));
- Bank b1 = new Bank("username", "password");
- //
- b1.addAccount(a1);
- b1.addAccount(a2);
- b1.addAccount(a3);
- b1.addAccount(a4);
- Scanner input = new Scanner(System.in);
- System.out.println("enter user ID");
- int n = input.nextInt();
- b1.findAccount(n);
- System.out.println("enter deposit amount");
- int d = input.nextInt();
- a2.deposit(d);
- a2.print();
- System.out.println("enter withraw amount");
- int W = input.nextInt();
- a3.withdraw(d);
- a3.print();
- System.out.println("enter street name");
- a4.getAddress().setstreet(input.next());
- System.out.println("enter street number");//prints the following
- a4.getAddress().setstreetNum(input.nextInt());
- System.out.println("enter suburb");//prints the following
- a4.getAddress().setsuburb(input.next());// simalir to streetNum
- System.out.println("enter city");//prints the following /
- a4.getAddress().setcity(input.next());//simalir to streetNum
- Address a;
- a = a4.getAddress();
- System.out.println(a);
- a4.getAddress().printAddress();
- a1.makePurchase(1, "liverpool", "cup", 30);
- a1.makePurchase(1, "liverpool", "book", 50);
- }
- }
- class Account {
- private String name;
- private int ID;
- private double balance;
- private Address address = new Address(3, "street", "suburb", "city");//obj of class Address
- ArrayList<Transaction> transactions = new ArrayList<Transaction>();
- ;
- public Account(String n, int i, double b, Address address) {
- this.name = n;
- this.ID = i;
- this.balance = b;
- }
- public void setname(String n) {
- name = n;
- }
- public String getname() {
- return name;
- }
- public void setid(int i) {
- ID = i;
- }
- public int getid() {
- return ID;
- }
- public void setbalance(double b) {
- balance = b;
- }
- public double getbalance() {
- return balance;
- }
- public boolean withdraw(double amount) {
- if (amount == balance || amount > balance) {
- System.out.println("successful");
- balance -= amount;
- return true;
- } else {
- System.out.println("Balance is not enough");
- return false;
- }
- }
- public void deposit(double amount) {
- if (amount > 0.0) {
- balance += amount;
- System.out.println("successful");
- } else if (amount < 0.0) {
- System.out.println("not successful");
- }
- }
- public Address getAddress() {
- return address;
- }
- public void print() {
- System.out.println( " " + this.ID + " " + this.balance + " " + this.name);
- }
- public void addTransaction(Transaction transaction) {
- transactions.add(transaction);
- }
- boolean makePurchase(int ID, String city, String description, double amount) {
- if (balance > amount) {
- balance -= amount;
- addTransaction(new Transaction(ID, city, description, amount));
- return true;
- } else {
- System.out.println("unsucessful " + " " + amount);
- return false;
- }
- }
- }
- class Address {
- private int streetNum;
- private String street;
- private String suburb;//var
- private String city;
- public Address(int streetNum, String street, String suburb, String city) {//con
- this.streetNum = streetNum;
- this.street = street;
- this.suburb = suburb;
- this.city = city;
- }
- public void setstreetNum(int Sn) {//setter
- streetNum = Sn;
- }
- public int getstreetNum() {
- return streetNum;
- }
- public void setstreet(String S) {
- street = S;
- }
- public String getStreet() {//getter
- return street;
- }
- public void setsuburb(String sub) {
- suburb = sub;
- }
- public String getsuburb() {
- return suburb;
- }
- public void setcity(String city) {
- city = city;
- }
- public String getcity() {
- return city;
- }
- public void printAddress() {//prints address
- System.out.println("street Address" + " " + this.streetNum + " " + this.street + " " + this.suburb + " " + this.city);
- }
- }
- class Transaction {
- private int ID;
- private String city;
- private String description;
- private double amount;
- public Transaction(int i, String c, String d, double a) {
- this.ID = i;
- this.city = c;
- this.description = d;
- this.amount = a;
- }
- public void setid(int i) {
- ID = i;
- }
- public int getid() {
- return ID;
- }
- public void setcity(String c) {
- city = c;
- }
- public String getcity() {
- return city;
- }
- public void setdes(String d) {
- description = d;
- }
- public String getdes() {
- return description;
- }
- public void setamount(double a) {
- amount = a;
- }
- public double getamount() {
- return amount;
- }
- public void printtrans() {
- System.out.println(this.ID);
- System.out.println(this.amount);
- System.out.println(this.city);
- System.out.println(this.description);
- }
- }
- class Bank {
- String username;
- String password;
- public String getusername() {
- return username;
- }
- public String getPassword() {
- return password;
- }
- public Bank(String u, String p) {
- u = username;
- p = password;
- }
- private ArrayList<Account> accounts = new ArrayList<Account>();
- private String adminUsername;
- private String adminPassword;
- boolean validateAdmin(String username, String password) {
- if (this.getusername() == adminUsername && this.getPassword() == adminPassword ) {
- return true;
- } else {
- return false;
- }
- // while (username == adminUsername && password == adminPassword) {
- }
- boolean addAccount(Account account) {
- accounts.add(account);
- return true;
- }
- Account findAccount(int accountID) {
- for (Account acc : accounts) {
- if (accountID == acc.getid()) {
- System.out.println("Account ID = " + acc.getid());
- return acc;
- } else {
- System.out.println("Account does not exist");
- }
- }
- return null;
- }
- public double calcTotalBalance() {
- double totalBalance = 0;
- for (Account acc : accounts) {
- totalBalance = totalBalance +acc.getbalance();
- }
- return totalBalance;
- }
- public void printAccounts() {
- for (Account acc : accounts) {
- System.out.println(acc);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement