Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Date;
- class CoordinateGenerator {
- private Random randomGenerator;
- public CoordinateGenerator()
- {
- Date now = new Date();
- long sec = now.getTime();
- randomGenerator = new Random(sec);
- }
- public int generateX()
- {
- int x = randomGenerator.nextInt(101);
- if(x < 5)
- {
- x = 0;
- }
- else if(x > 95)
- {
- x = 100;
- }
- else
- {
- x = randomGenerator.nextInt(99) + 1;
- }
- return x;
- }
- public int generateY()
- {
- int y = randomGenerator.nextInt(101);
- if(y < 5)
- {
- y = 0;
- }
- else if(y > 95)
- {
- y = 50;
- }
- else
- {
- y = randomGenerator.nextInt(49) + 1;
- }
- return y;
- }
- }
- class Out extends Exception
- {
- public Out()
- {
- super("Out!");
- }
- }
- class Gol extends Exception
- {
- public Gol()
- {
- super("Gol!");
- }
- }
- class Corner extends Exception
- {
- public Corner()
- {
- super("Corner!");
- }
- }
- class Minge
- {
- private int x, y;
- public Minge(int x, int y)
- {
- this.x=x;
- this.y=y;
- }
- public int detX()
- {
- return x;
- }
- public int detY()
- {
- return y;
- }
- public void suteaza() throws Out, Gol, Corner
- {
- CoordinateGenerator x_new = new CoordinateGenerator();
- CoordinateGenerator y_new = new CoordinateGenerator();
- x=x_new.generateX();
- y=y_new.generateY();
- if(y==0 || y==50)
- throw new Out();
- else if ((x==0||x==100)&&(y>=20&&y<=30))
- throw new Gol();
- else if ((x==0||x==100)&&((0<y)&&(y<20)||(30<y)&&(y<50)))
- throw new Corner();
- }
- }
- class Joc
- {
- private int nr_goluri1, nr_goluri2;
- private int nr_out, nr_corner;
- private String echipa1, echipa2;
- public Joc(String e1, String e2)
- {
- this.echipa1 = e1;
- this.echipa2 = e2;
- }
- public String toString()
- {
- String s= " ";
- s = s+nr_goluri1+" "+echipa1+"-"+echipa2+" "+nr_goluri2+" ";
- s = s+"Numar outuri: "+nr_out+" Numar Cornere: "+nr_corner+" ";
- return s;
- }
- public void simuleaza()
- {
- Minge m= new Minge(50,25);
- int i;
- for(i=0;i<1000;i++)
- try{
- m.suteaza();
- }
- catch(Out e)
- {
- Minge m1 = new Minge (m.detX(), m.detY());
- }
- catch(Gol e)
- {
- Minge m1 = new Minge (50,25);
- }
- catch(Corner e)
- {
- }
- }
- }
- class Main
- {
- public static void main (String argv[])
- {
- Joc m1= new Joc("UTA Arad", "Poli Timisoara");
- System.out.println(m1.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement