added limits
This commit is contained in:
parent
834a48175f
commit
8950f8d153
@ -5,17 +5,9 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="f370439b-3b86-4211-acf9-0118b90c4643" name="Changes" comment="prototype upload">
|
<list default="true" id="f370439b-3b86-4211-acf9-0118b90c4643" name="Changes" comment="prototype upload">
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/encodings.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 afterPath="$PROJECT_DIR$/.idea/jarRepositories.xml" 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" />
|
||||||
<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" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
@ -9,9 +9,12 @@ public class ATM
|
|||||||
public static void main( String[] args )
|
public static void main( String[] args )
|
||||||
{
|
{
|
||||||
Scanner scanner = new Scanner(System.in);
|
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[0] = new Card(1, "credit", "0001");
|
||||||
cards[1] = new Card(2, "debit", "1110");
|
cards[1] = new Card(2, "debit", "1110");
|
||||||
|
cards[2] = new Card(2, "debit", "1110");
|
||||||
|
cards[2].addFunds(1000000);
|
||||||
while(true){
|
while(true){
|
||||||
System.out.println(cards[0] + "\n" + cards[1] + "\n" + "Wsuń kartę(podaj id):");
|
System.out.println(cards[0] + "\n" + cards[1] + "\n" + "Wsuń kartę(podaj id):");
|
||||||
int index = scanner.nextInt()-1;
|
int index = scanner.nextInt()-1;
|
||||||
@ -36,23 +39,35 @@ public class ATM
|
|||||||
case 1 -> {
|
case 1 -> {
|
||||||
System.out.println("Wprowadź kwotę:");
|
System.out.println("Wprowadź kwotę:");
|
||||||
insertedAmount = scanner.nextInt();
|
insertedAmount = scanner.nextInt();
|
||||||
cards[index].withdrawFunds(insertedAmount);
|
if (cards[index].isLimitExceeded(insertedAmount)) {
|
||||||
System.out.println("ksz ksz ksz ksz...");
|
System.out.println("Niewystarczająca ilość środków");
|
||||||
|
} else {
|
||||||
|
cards[index].withdrawFunds(insertedAmount);
|
||||||
|
System.out.println("ksz ksz ksz ksz...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case 2 -> {
|
case 2 -> {
|
||||||
System.out.println("Wprowadź kwotę:");
|
System.out.println("Wprowadź kwotę:");
|
||||||
insertedAmount = scanner.nextInt();
|
insertedAmount = scanner.nextInt();
|
||||||
cards[index].addFunds(insertedAmount);
|
if(cash-insertedAmount<0){System.out.println("nie wystarczająca ilość środków w maszynie");}
|
||||||
System.out.println("am am am...");
|
else{
|
||||||
|
cards[index].addFunds(insertedAmount);
|
||||||
|
System.out.println("am am am...");
|
||||||
|
cash+=insertedAmount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case 3 -> {
|
case 3 -> {
|
||||||
System.out.println("Wprowadź id karty do przelewu:");
|
System.out.println("Wprowadź id karty do przelewu:");
|
||||||
int transferCard = scanner.nextInt();
|
int transferCard = scanner.nextInt();
|
||||||
System.out.println("Wprowadź kwotę:");
|
System.out.println("Wprowadź kwotę:");
|
||||||
insertedAmount = scanner.nextInt();
|
insertedAmount = scanner.nextInt();
|
||||||
cards[index].withdrawFunds(insertedAmount);
|
if (cards[index].isLimitExceeded(insertedAmount)) {
|
||||||
cards[transferCard - 1].addFunds(insertedAmount);
|
System.out.println("Niewystarczająca ilość środków");
|
||||||
System.out.println("siup siup siup...");
|
} else {
|
||||||
|
cards[index].withdrawFunds(insertedAmount);
|
||||||
|
cards[transferCard - 1].addFunds(insertedAmount);
|
||||||
|
System.out.println("siup siup siup...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case 4 -> {
|
case 4 -> {
|
||||||
System.out.println("Wprowadź kwotę:");
|
System.out.println("Wprowadź kwotę:");
|
||||||
|
@ -26,6 +26,13 @@ public class Card {
|
|||||||
this.balance -= amount;
|
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) {
|
public Card(int id, String type, String PIN) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
Loading…
Reference in New Issue
Block a user