Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. abstract class Ball {
  4. private int x;
  5. private int y;
  6. private Random r = new Random();
  7.  
  8. public Ball(int a,int b){
  9. x=a;
  10. y=b;
  11. }
  12.  
  13. public void play(Ball b) throws outException,goalException,cornerException {
  14. int x = r.nextInt(101);
  15. int y = r.nextInt(51);
  16.  
  17. if(y==0 || y==50)
  18. throw new outException();
  19.  
  20. else if ((x==0 || x==100)&&(y>=20 && y<=30))
  21. throw new goalException();
  22.  
  23. else if ((x==0 || x==100)&&((y<0 && y<20) || (y<30 && y<50)))
  24. throw new cornerException();
  25. }
  26.  
  27. }
  28.  
  29.  
  30. class outException extends Exception {
  31.  
  32. public outException(){
  33. super("That's a side throw!\n");
  34. }
  35. }
  36.  
  37. class cornerException extends Exception {
  38.  
  39. public cornerException() {
  40.  
  41. super("Corner kick! Let's see what they're up to!!\n");
  42. }
  43. }
  44.  
  45. class goalException extends Exception {
  46.  
  47. public goalException() {
  48.  
  49. super("Look at that goal! Great finish, great precission, great player! Let's see the replay!\n");
  50. }
  51. }
  52.  
  53. class Game {
  54. private String team1;
  55. private String team2;
  56.  
  57. private int score;
  58. private int outs;
  59. private int corners;
  60.  
  61. public Game(String team1, String team2) {
  62. this.team1 = team1;
  63. this.team2 = team2;
  64.  
  65. }
  66.  
  67. public String toString() {
  68. return "The score is: " + score + " \n We had " + outs + " outs in this game\n" + "And we had " + corners + " corners in this game\n";
  69. }
  70.  
  71. public void playGame() {
  72.  
  73. for(int i = 0; i < 2000; i++)
  74.  
  75. }
  76.  
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement