Advertisement
Mihael_13

Part 1 Buda Task

May 20th, 2024
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.92 KB | Software | 0 0
  1. public class Main
  2. {
  3.     public static void main(String[] args) {
  4.         BankAccount DSK = new BankAccount("DSK", 13);
  5.         DSK.withdraw(13);
  6.         DSK.deposit(100);
  7.         System.out.println(DSK.toPrint());
  8.         BankAccount BNB = new BankAccount("BNB", 13);
  9.        
  10.         Person Jivko = new Person("Jivko", "Jivkov", DSK, BNB);
  11.         Jivko.printPerson();
  12.  
  13.     }
  14. }
  15.  
  16. class BankAccount{
  17.    
  18.     String bankName;
  19.     double balance;
  20.  
  21.     public BankAccount(String bankName, double balance){
  22.        
  23.         this.bankName = bankName;
  24.         this.balance = balance;
  25.        
  26.     }  
  27.    
  28.     public void withdraw(double WithDraw){
  29.        
  30.         balance = balance - WithDraw;
  31.        
  32.     }
  33.    
  34.     public void deposit(double Deposit){
  35.        
  36.         balance = balance + Deposit;
  37.        
  38.     }
  39.    
  40.     String toPrint(){
  41.        
  42.         String output = "Банкова сметка на банка " + bankName + " с баланс " + balance + " лв";
  43.         return output;
  44.     }
  45.    
  46.     public String getBankName(){
  47.        
  48.         return bankName;
  49.        
  50.     }
  51.    
  52.     public double getBalance(){
  53.        
  54.         return balance;
  55.        
  56.     }
  57.    
  58.     public void setBankName(String bankName){
  59.         this.bankName = bankName;
  60.     }
  61.    
  62.     public void setBalance(double balance){
  63.         this.balance = balance;
  64.     }
  65.    
  66.     public BankAccount(){}
  67. }
  68.  
  69. class Person extends BankAccount{
  70.    
  71.     String firstName;
  72.     String lastName;
  73.     BankAccount checkingAccount;
  74.     BankAccount savingsAccount;
  75.    
  76.     public Person(String firstName, String lastName, BankAccount checkingAccount, BankAccount savingsAccount){
  77.        
  78.         this.firstName = firstName;
  79.         this.lastName = lastName;
  80.         this.checkingAccount = checkingAccount;
  81.         this.savingsAccount = savingsAccount;
  82.        
  83.     }
  84.    
  85.     public void setFirstName(String firstName){
  86.        
  87.         this.firstName = firstName;
  88.        
  89.     }
  90.    
  91.     public void setLastName(String lastName){
  92.        
  93.         this.lastName = lastName;
  94.        
  95.     }
  96.    
  97.     public void setCheckingAccount(BankAccount checkingAccount){
  98.        
  99.         this.checkingAccount = checkingAccount;
  100.        
  101.     }
  102.    
  103.     public void setSavingsAccount(BankAccount savingsAccount){
  104.        
  105.         this.savingsAccount = savingsAccount;
  106.        
  107.     }
  108.    
  109.     public String getFirstName(){
  110.        
  111.         return firstName;
  112.        
  113.     }
  114.    
  115.     public String getLastName(){
  116.        
  117.         return lastName;
  118.        
  119.     }
  120.    
  121.     public BankAccount getCheckingAccount(){
  122.        
  123.         return checkingAccount;
  124.        
  125.     }
  126.    
  127.     public BankAccount getSavingsAccount(){
  128.        
  129.         return savingsAccount;
  130.        
  131.     }
  132.    
  133.     public void printPerson(){
  134.        
  135.         System.out.printf("%s %s %s %s", firstName, lastName, checkingAccount.toPrint(), savingsAccount.toPrint());
  136.        
  137.     }
  138.    
  139. }
Tags: Java
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement