Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class Lesson10Task {
- public static void main(String[] args) {
- CreditCard credit = new CreditCard(1000,false);
- credit.setGetMoney(15);
- credit.setAddMoney(50);
- credit.calcWithdraw();
- credit.calcPlus();
- credit.output();
- DebitCard debit = new DebitCard(1000,true,2);
- debit.setGetMoney(10);
- debit.setAddMoney(20);
- debit.calcWithdraw();
- debit.calcPlus();
- debit.output();
- PrivilegeCard privilege = new PrivilegeCard(100);
- privilege.setGetMoney(50);
- privilege.setAddMoney(200);
- privilege.calcWithdraw();
- privilege.calcPlus();
- privilege.output();
- }
- }
- package com.company;
- public class Card {
- double moneyOnCard, getMoney,addMoney,minus,plus,takenMoney,addedMoney;
- double percent = 0;
- double anotherATM = 0.5;
- boolean bankATM = true;
- public Card(double moneyOnCard) {
- this.moneyOnCard = moneyOnCard;
- }
- public void setGetMoney(double getMoney) {
- this.getMoney = getMoney;
- }
- public void setAddMoney(double addMoney) {
- this.addMoney = addMoney;
- }
- }
- public class CreditCard extends Card{
- public CreditCard(double moneyOnCard, boolean bankATM){
- super(moneyOnCard);
- }
- void calcWithdraw(){
- if (bankATM == true) {
- minus = moneyOnCard - (getMoney - percent);
- }
- else{
- minus = moneyOnCard - getMoney - ((getMoney * anotherATM)/100);
- }
- takenMoney = moneyOnCard - minus;
- }
- void calcPlus(){
- plus = moneyOnCard + addMoney;
- addedMoney = plus - moneyOnCard;
- }
- void output(){
- System.out.println("=== Credit Card ===");
- System.out.println("Money count after withdraw: " + minus);
- System.out.println("Taken money: " + takenMoney);
- System.out.println();
- System.out.println("Money count after deposit: " + plus);
- System.out.println("Added money: " + addedMoney);
- System.out.println();
- System.out.println();
- }
- }
- package com.company;
- public class DebitCard extends Card {
- double deposit = 1;
- double withdrawWithDebit;
- int monthNumber;
- public DebitCard(int moneyOnCard, boolean bankATM, int monthNumber) {
- super(moneyOnCard);
- this.monthNumber = monthNumber;
- }
- void calcWithdraw() {
- System.out.println("=== Debit Card ===");
- System.out.println("==Money count with 1% deposit==");
- System.out.println();
- if (bankATM == true) {
- withdrawWithDebit = moneyOnCard + (moneyOnCard * (deposit / 100 / 12) * monthNumber) - getMoney;
- } else {
- withdrawWithDebit = moneyOnCard + (moneyOnCard * (deposit / 100 / 12) * monthNumber) - getMoney - ((getMoney * (anotherATM / 100)));
- }
- takenMoney = moneyOnCard - withdrawWithDebit;
- }
- void calcPlus(){
- plus = (moneyOnCard + addMoney) + (addMoney *((deposit/100/12)*monthNumber));
- addedMoney = plus - moneyOnCard;
- }
- void output(){
- System.out.println("Money count after withdraw: " +withdrawWithDebit + " in a " + monthNumber + " month");
- System.out.println("Taken money + deposit: " + takenMoney);
- System.out.println();
- System.out.println("Money count after deposit: " + plus);
- System.out.println("Added money + deposit: " + addedMoney + " in a " + monthNumber + " month");
- System.out.println();
- System.out.println();
- }
- }
- package com.company;
- public class PrivilegeCard extends Card {
- public PrivilegeCard (double moneyOnCard){
- super(moneyOnCard);
- }
- void calcWithdraw() {
- minus = moneyOnCard - (getMoney - percent);
- takenMoney = moneyOnCard - minus;
- }
- void calcPlus() {
- plus = moneyOnCard + addMoney;
- addedMoney = plus - moneyOnCard;
- }
- void output() {
- System.out.println("=== Privilege Card ===");
- System.out.println("Money count after withdraw: " + minus);
- System.out.println("Taken money: " + takenMoney);
- System.out.println();
- System.out.println("Money count after deposit: " + plus);
- System.out.println("Added money: " + addedMoney);
- System.out.println();
- }
- }
- === Credit Card ===
- Money count after withdraw: 985.0
- Taken money: 15.0
- Money count after deposit: 1050.0
- Added money: 50.0
- === Debit Card ===
- ==Money count with 1% deposit==
- Money count after withdraw: 991.6666666666666 in a 2 month
- Taken money + deposit: 8.333333333333371
- Money count after deposit: 1020.0333333333333
- Added money + deposit: 20.033333333333303 in a 2 month
- === Privilege Card ===
- Money count after withdraw: 50.0
- Taken money: 50.0
- Money count after deposit: 300.0
- Added money: 200.0
- It is
Add Comment
Please, Sign In to add comment