Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- class Out extends Exception{
- public Out(){
- super("Out!!");
- }
- }
- class Goal extends Exception{
- public Goal(){
- super("Goal!!");
- }
- }
- class Corner extends Exception{
- public Corner(){
- super("Corner!!");
- }
- }
- public class Ball {
- private int x,y;
- private Random aux = new Random();
- public Ball(int x, int y){
- this.x = x;
- this.y = y;
- }
- public void play() throws Out, Goal, Corner{
- x = aux.nextInt(100);
- y = aux.nextInt(50);
- if(y == 0 || y == 50)
- throw new Out();
- if(x == 0 || x == 100){
- if(y >= 20 && y<=30)
- throw new Goal();
- if((y > 0 && y < 20) || (y > 30 && y <50))
- throw new Corner();
- }
- }
- }
- class Game {
- //Ball ball = new Ball(50,25);
- private String Team1, Team2;
- private int Score1, Score2, Outs, Corners;
- public Game(String Team1, String Team2){
- this.Team1 = Team1;
- this.Team2 = Team2;
- }
- public String toString(){
- return Team1 + " " + Score1 + " " + Score2 + " " + Team2 + " outs: " + Outs + " corners " + Corners;
- }
- /*
- try {
- ball.play();
- ball.play();
- ball.play();ball.play();
- ball.play();
- ball.play();ball.play();
- ball.play();
- ball.play();
- }
- catch(Exception e)
- {
- System.out.println(e);
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement