fork download
  1.  
  2. import java.io.File;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.util.Random;
  6.  
  7. public class Client implements Runnable {
  8. static Bankacc bank = new Bankacc();
  9. private int id = 1;
  10.  
  11. public static void main(String[] args) throws InterruptedException {
  12. File myfil = new File("D:\\banklog.txt");
  13. try {
  14. FileWriter fw = new FileWriter(myfil);
  15. } catch (IOException e) {
  16. e.printStackTrace();
  17. }
  18.  
  19. Client client = new Client();
  20. Thread one = new Thread(client);
  21. Thread two = new Thread(client);
  22. Thread three = new Thread(client);
  23. Thread four = new Thread(client);
  24. Thread five = new Thread(client);
  25. Thread six = new Thread(client);
  26. Thread seven = new Thread(client);
  27. Thread eight = new Thread(client);
  28.  
  29. one.setName("Андрей");
  30. two.setName("Борис");
  31. three.setName("Валентин");
  32. four.setName("Галя");
  33. five.setName("Денис");
  34. six.setName("Егор");
  35. seven.setName("Игорь");
  36. eight.setName("Екатерина");
  37.  
  38. one.start();
  39. two.start();
  40. three.start();
  41. four.start();
  42. five.start();
  43. six.start();
  44. seven.start();
  45. eight.start();
  46. two.join();
  47. three.join();
  48. four.join();
  49. five.join();
  50. six.join();
  51. seven.join();
  52. eight.join();
  53. }
  54.  
  55. public void run() {
  56. Random r = new Random();
  57.  
  58. for (int i = 0; i < 20; i++) {
  59. try {
  60. Thread.sleep(250);
  61. } catch (InterruptedException e1) {
  62. e1.printStackTrace();
  63. }
  64. int fate = r.nextInt(4);
  65. int currsumm = r.nextInt(100) + 50;
  66. if (fate == 1) {
  67. bank.putOn(currsumm);
  68. String s = getId() + " " + Thread.currentThread().getName() + " Положил на счёт " + currsumm + " Cейчас на счёту: " + bank.getBalance();
  69. System.out.println(s);
  70. idPlus();
  71. } else {
  72. if (bank.getBalance() <= 0) {
  73. String s = getId() + " " + "Извини " + Thread.currentThread().getName() + " но деньги закончились";
  74. System.out.println(s);
  75. try {
  76. Write.log(s);
  77. } catch (Exception e) {
  78. e.printStackTrace();
  79. }
  80. Thread.currentThread().interrupt();
  81. idPlus();
  82. i = 20;
  83. }
  84. if (bank.getBalance() < currsumm) {
  85. int temp = bank.getBalance();
  86. bank.withdraw(bank.getBalance());
  87. String s = getId() + " " + Thread.currentThread().getName() + " Хотел снять со счёта " + currsumm + " .Но на счету осталось лишь " + temp + " Cейчас на счёту: " + bank.getBalance();
  88. System.out.println(s);
  89. try {
  90. Write.log(s);
  91. } catch (Exception e) {
  92. e.printStackTrace();
  93. }
  94. idPlus();
  95. i = 20;
  96. } else {
  97. bank.withdraw(currsumm);
  98. String s = getId() + " " + Thread.currentThread().getName() + " Снял со счёта " + currsumm + " Cейчас на счёту: " + bank.getBalance();
  99. System.out.println(s);
  100. try {
  101. Write.log(s);
  102. } catch (Exception e) {
  103. e.printStackTrace();
  104. }
  105. idPlus();
  106. }
  107. }
  108. }
  109. Thread.yield();
  110. }
  111.  
  112. public synchronized int idPlus() {
  113. return id++;
  114. }
  115. public synchronized int getId() {
  116. return id;
  117. }
  118. }
  119.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:7: error: class Client is public, should be declared in a file named Client.java
public class Client implements Runnable {
       ^
Main.java:8: error: cannot find symbol
	static Bankacc bank = new Bankacc();
	       ^
  symbol:   class Bankacc
  location: class Client
Main.java:8: error: cannot find symbol
	static Bankacc bank = new Bankacc();
	                          ^
  symbol:   class Bankacc
  location: class Client
Main.java:76: error: cannot find symbol
						Write.log(s);
						^
  symbol:   variable Write
  location: class Client
Main.java:90: error: cannot find symbol
						Write.log(s);
						^
  symbol:   variable Write
  location: class Client
Main.java:101: error: cannot find symbol
						Write.log(s);
						^
  symbol:   variable Write
  location: class Client
6 errors
stdout
Standard output is empty