added limits

This commit is contained in:
Wiktor Duda 2022-10-12 17:48:33 +02:00
parent 834a48175f
commit 8950f8d153
3 changed files with 33 additions and 19 deletions

View File

@ -5,17 +5,9 @@
</component>
<component name="ChangeListManager">
<list default="true" id="f370439b-3b86-4211-acf9-0118b90c4643" name="Changes" comment="prototype upload">
<change afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/jarRepositories.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/org/example/ATM.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/org/example/App.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/org/example/Card.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/java/org/example/AppTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/example/ATM.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/example/ATM.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/example/Card.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/example/Card.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

@ -9,9 +9,12 @@ public class ATM
public static void main( String[] args )
{
Scanner scanner = new Scanner(System.in);
Card[] cards = new Card[2];
int cash = 10000;
Card[] cards = new Card[3];
cards[0] = new Card(1, "credit", "0001");
cards[1] = new Card(2, "debit", "1110");
cards[2] = new Card(2, "debit", "1110");
cards[2].addFunds(1000000);
while(true){
System.out.println(cards[0] + "\n" + cards[1] + "\n" + "Wsuń kartę(podaj id):");
int index = scanner.nextInt()-1;
@ -36,23 +39,35 @@ public class ATM
case 1 -> {
System.out.println("Wprowadź kwotę:");
insertedAmount = scanner.nextInt();
cards[index].withdrawFunds(insertedAmount);
System.out.println("ksz ksz ksz ksz...");
if (cards[index].isLimitExceeded(insertedAmount)) {
System.out.println("Niewystarczająca ilość środków");
} else {
cards[index].withdrawFunds(insertedAmount);
System.out.println("ksz ksz ksz ksz...");
}
}
case 2 -> {
System.out.println("Wprowadź kwotę:");
insertedAmount = scanner.nextInt();
cards[index].addFunds(insertedAmount);
System.out.println("am am am...");
if(cash-insertedAmount<0){System.out.println("nie wystarczająca ilość środków w maszynie");}
else{
cards[index].addFunds(insertedAmount);
System.out.println("am am am...");
cash+=insertedAmount;
}
}
case 3 -> {
System.out.println("Wprowadź id karty do przelewu:");
int transferCard = scanner.nextInt();
System.out.println("Wprowadź kwotę:");
insertedAmount = scanner.nextInt();
cards[index].withdrawFunds(insertedAmount);
cards[transferCard - 1].addFunds(insertedAmount);
System.out.println("siup siup siup...");
if (cards[index].isLimitExceeded(insertedAmount)) {
System.out.println("Niewystarczająca ilość środków");
} else {
cards[index].withdrawFunds(insertedAmount);
cards[transferCard - 1].addFunds(insertedAmount);
System.out.println("siup siup siup...");
}
}
case 4 -> {
System.out.println("Wprowadź kwotę:");

View File

@ -26,6 +26,13 @@ public class Card {
this.balance -= amount;
}
public boolean isLimitExceeded(int amount){
if(this.balance-amount<0){
return true;
}
return false;
}
public Card(int id, String type, String PIN) {
this.id = id;
this.type = type;