Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Bank;
- public abstract class Accaunt {
- private static int id = 0;
- private int accauntID, balance, fee, loan;
- protected int OD =0;
- private boolean gift = false;
- private String name;
- public Accaunt(int balance, String name, int fee) {
- id += 1;
- this.accauntID = id;
- this.balance = balance;
- this.name = name;
- this.fee = fee;
- }
- public int getId() {
- return id;
- }
- public int getBalance() {
- return balance;
- }
- public String getName() {
- return name;
- }
- public int getOD() {
- return OD;
- }
- public void setOD(int OD) {
- if(this instanceof LargeBuisness) { // large buisness have x3 OD
- this.OD = OD*3;
- }else{
- this.OD = OD;
- }
- }
- public void deposite(int amount) {
- balance += amount - (amount / 100 * fee);
- }
- public boolean withdrow(int amount) {
- int amountWithFee = amount - (amount / 100 * fee);
- if (amount <= this.OD +this.balance) {
- balance -= amountWithFee;
- return true;
- } else {
- return false;
- }
- }
- public boolean takeLoan(int amount) { // to take loan
- if (this instanceof Regular || this instanceof Student || this instanceof Buisness) {
- if (this instanceof LargeBuisness){
- this.loan = loan *3; // large buisness have x3 loan
- return true;
- }
- loan = amount;
- return true;
- }
- else{
- return false;
- }
- }
- public int getLoan() {
- return loan;
- }
- public void takeGift() {
- if (this instanceof Student) {
- this.gift = true;
- } else {
- this.gift = false;
- }
- }
- public boolean getGift(){
- return this.gift;
- }
- public String toString() {
- return "Accaunt " +
- "id=" + accauntID +
- ", balance=" + balance +
- ", name='" + name + '\'';
- }
- }
- =======================================================
- package Bank;
- public abstract class Youngth extends Accaunt {
- public static final int FEE = 0;
- public Youngth(int balance, String name) {
- super(balance, name, FEE);
- }
- }
- @Override
- public String toString() {
- return super.toString() + ", have a gift: " + super.getGift();
- }
- =======================================================
- package Bank;
- public abstract class Buisness extends Accaunt {
- public static final int FEE = 1;
- public Buisness(int balance, String name) {
- super(balance, name, FEE);
- }
- @Override
- public String toString() {
- return super.toString() + ", loan: " + super.getLoan(); //toString overriding cause we have a loan
- }
- }
- =======================================================
- package Bank;
- public class Regular extends Accaunt {
- public static final int FEE = 3;
- public Regular(int balance, String name) {
- super(balance, name, FEE);
- super.setOD(1500); //OD for example
- }
- @Override
- public String toString() {
- return super.toString() + ", loan: " + super.getLoan(); //toString overriding cause we have a loan
- }
- }
- ======================================================
- package Bank;
- public class Soldier extends Youngth{
- public Soldier(int balance, String name) {
- super(balance, name);
- super.setOD(1000); //OD for example
- }
- }
- ======================================================
- package Bank;
- public class Teenager extends Youngth {
- public Teenager(int balance, String name) {
- super(balance, name);
- }
- }
- =======================================================
- package Bank;
- public class Student extends Youngth {
- public Student(int balance, String name) {
- super(balance, name);
- super.setOD(500);
- }
- @Override
- public String toString() {
- return super.toString() + ", loan: " + super.getLoan(); //toString overriding cause we have a loan
- }
- }
- =====================================================
- package Bank;
- public class RegBuisness extends Buisness{
- public RegBuisness(int balance, String name) {
- super(balance, name);
- }
- }
- =====================================================
- package Bank;
- public class LargeBuisness extends Buisness {
- public LargeBuisness(int balance, String name) {
- super(balance, name);
- }
- }
- ================== main ==================================
- import java.util.Scanner;
- import Bank.*;
- public class objectsClassesFirstLesson {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- //makes 6 other types of accaunts
- Accaunt new1 = new Regular(100, "Jhon");
- Accaunt new2 = new Soldier(200, "Bob");
- Accaunt new3 = new Teenager(300, "Kate");
- Accaunt new4 = new Student(400, "Ann");
- Accaunt new5 = new RegBuisness(500, "Jim");
- Accaunt new6 = new LargeBuisness(600, "Gale");
- new1.takeLoan(1000); // taking a loan
- new2.deposite(699); // adding some money to accaunt
- new3.withdrow(100); // taking some money from accaunt
- new4.takeGift(); // takong a gift for student
- new6.setOD(1000); // seting OD (large buisness X3)
- new6.withdrow(3000); // see we can withdraw fro x3 OD
- System.out.println(new1+"\n"+new2+"\n"+new3+"\n"+new4+"\n"+new5+"\n"+new6+"\n");
- }
- }
Add Comment
Please, Sign In to add comment