Goodiny777

Multyply bank accaunts JAVA homework

Jan 30th, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.65 KB | None | 0 0
  1. package Bank;
  2.  
  3. public abstract class Accaunt {
  4.     private static int id = 0;
  5.     private int accauntID, balance, fee, loan;
  6.     protected int OD =0;
  7.     private boolean gift = false;
  8.     private String name;
  9.  
  10.     public Accaunt(int balance, String name, int fee) {
  11.         id += 1;
  12.         this.accauntID = id;
  13.         this.balance = balance;
  14.         this.name = name;
  15.         this.fee = fee;
  16.     }
  17.  
  18.     public int getId() {
  19.         return id;
  20.     }
  21.  
  22.     public int getBalance() {
  23.         return balance;
  24.     }
  25.  
  26.     public String getName() {
  27.         return name;
  28.     }
  29.  
  30.     public int getOD() {
  31.         return OD;
  32.     }
  33.  
  34.     public void setOD(int OD) {
  35.         if(this instanceof  LargeBuisness) {   // large buisness have x3 OD
  36.             this.OD = OD*3;
  37.         }else{
  38.             this.OD = OD;
  39.         }
  40.     }
  41.  
  42.     public void deposite(int amount) {
  43.         balance += amount - (amount / 100 * fee);
  44.     }
  45.  
  46.     public boolean withdrow(int amount) {
  47.         int amountWithFee = amount - (amount / 100 * fee);
  48.         if (amount <= this.OD +this.balance) {
  49.             balance -= amountWithFee;
  50.             return true;
  51.         } else {
  52.             return false;
  53.         }
  54.     }
  55.  
  56.     public boolean takeLoan(int amount) {  // to take loan
  57.         if (this instanceof Regular || this instanceof Student || this instanceof Buisness) {
  58.             if (this instanceof LargeBuisness){
  59.                 this.loan = loan *3;  // large buisness have x3 loan
  60.                 return true;
  61.             }
  62.             loan = amount;
  63.             return true;
  64.         }
  65.         else{
  66.             return false;
  67.         }
  68.     }
  69.  
  70.     public int getLoan() {
  71.         return loan;
  72.     }
  73.  
  74.     public void takeGift() {
  75.         if (this instanceof Student) {
  76.             this.gift = true;
  77.         } else {
  78.             this.gift = false;
  79.         }
  80.     }
  81.  
  82.     public  boolean getGift(){
  83.         return this.gift;
  84.     }
  85.  
  86.     public String toString() {
  87.         return "Accaunt " +
  88.                 "id=" + accauntID +
  89.                 ", balance=" + balance +
  90.                 ", name='" + name + '\'';
  91.     }
  92. }
  93.  
  94.  
  95. =======================================================
  96. package Bank;
  97.  
  98. public abstract class Youngth extends Accaunt {
  99.     public static final int FEE = 0;
  100.  
  101.     public Youngth(int balance, String name) {
  102.         super(balance, name, FEE);
  103.     }
  104. }
  105.  
  106. @Override
  107. public String toString() {
  108.     return  super.toString() + ", have a gift: " + super.getGift();
  109.     }
  110.  
  111. =======================================================
  112. package Bank;
  113.  
  114. public abstract class Buisness extends Accaunt {
  115.     public static final int FEE = 1;
  116.     public Buisness(int balance, String name) {
  117.         super(balance, name, FEE);
  118.     }
  119.     @Override
  120.     public String toString() {
  121.         return  super.toString() + ", loan: " + super.getLoan(); //toString overriding cause we have a loan
  122.     }
  123. }
  124.  
  125.  
  126. =======================================================
  127. package Bank;
  128.  
  129. public class Regular extends Accaunt {
  130.     public static final int FEE = 3;
  131.  
  132.     public Regular(int balance, String name) {
  133.         super(balance, name, FEE);
  134.         super.setOD(1500); //OD for example
  135.     }
  136.  
  137.     @Override
  138.     public String toString() {
  139.         return  super.toString() + ", loan: " + super.getLoan(); //toString overriding cause we have a loan
  140.     }
  141. }
  142.  
  143. ======================================================
  144. package Bank;
  145.  
  146. public class Soldier extends Youngth{
  147.  
  148.     public Soldier(int balance, String name) {
  149.         super(balance, name);
  150.         super.setOD(1000); //OD for example
  151.     }
  152. }
  153.  
  154. ======================================================
  155. package Bank;
  156.  
  157. public class Teenager extends Youngth {
  158.     public Teenager(int balance, String name) {
  159.         super(balance, name);
  160.     }
  161. }
  162.  
  163. =======================================================
  164. package Bank;
  165.  
  166. public class Student extends Youngth {
  167.     public Student(int balance, String name) {
  168.         super(balance, name);
  169.         super.setOD(500);
  170.     }
  171.     @Override
  172.     public String toString() {
  173.         return  super.toString() + ", loan: " + super.getLoan(); //toString overriding cause we have a loan
  174.     }
  175. }
  176.  
  177. =====================================================
  178. package Bank;
  179.  
  180. public class RegBuisness extends Buisness{
  181.     public RegBuisness(int balance, String name) {
  182.         super(balance, name);
  183.     }
  184. }
  185.  
  186.  
  187. =====================================================
  188.  
  189. package Bank;
  190.  
  191. public class LargeBuisness extends Buisness {
  192.     public LargeBuisness(int balance, String name) {
  193.         super(balance, name);
  194.     }
  195. }
  196.  
  197.  
  198. ================== main ==================================
  199. import java.util.Scanner;
  200. import Bank.*;
  201. public class objectsClassesFirstLesson {
  202.     public static void main(String[] args) {
  203.         Scanner sc = new Scanner(System.in);
  204.        
  205.         //makes 6 other types of accaunts
  206.         Accaunt new1 = new Regular(100, "Jhon");
  207.         Accaunt new2 = new Soldier(200, "Bob");
  208.         Accaunt new3 = new Teenager(300, "Kate");
  209.         Accaunt new4 = new Student(400, "Ann");
  210.         Accaunt new5 = new RegBuisness(500, "Jim");
  211.         Accaunt new6 = new LargeBuisness(600, "Gale");
  212.  
  213.         new1.takeLoan(1000); // taking a loan
  214.         new2.deposite(699); // adding some money to accaunt
  215.         new3.withdrow(100); // taking some money from accaunt
  216.  
  217.         new4.takeGift(); // takong a gift for student
  218.  
  219.         new6.setOD(1000); // seting OD (large buisness X3)
  220.         new6.withdrow(3000); // see we can withdraw fro x3 OD
  221.  
  222.         System.out.println(new1+"\n"+new2+"\n"+new3+"\n"+new4+"\n"+new5+"\n"+new6+"\n");
  223.     }
  224. }
Add Comment
Please, Sign In to add comment