public class Domino private int leftValue private int right

public class Domino {
private int leftValue;
private int rightValue;

public Domino(int leftValue, int rightValue) {
this.leftValue = leftValue;
this.rightValue = rightValue;
}

public int getLeftValue() {
return leftValue;
}

public int getRightValue() {
return rightValue;
}
}
//This creates the Array
Domino[] dominos = new Domino[] {
new Domino(2, 3)
new Domino(3, 2)
new Domino(2, 5)
new Domino(2, 5)
}

//This part Loops and matchs left and right values
Domino previous = null
for (Domino current : dominos) {
if (previous != null) {
if (current.getLeftValue() != previous.getRightValue()) {
throw new Exception(\"Illegal\")
}
}
previous = current
}

I am getting an error on line 19 that says this....

File: /Users/Stephanie/Desktop/Domino.java [line: 19]
Error: /Users/Stephanie/Desktop/Domino.java:19: class, interface, or enum expected

But I don\'t know how to fix that.

Solution

Note: I just rectified the compile time errors .But I dont know the requirement.So Am not changing the logic which you mentioned.Check this code once.Thank You.

______________________

Domino.java

public class Domino {
   private int leftValue;
   private int rightValue;

   public Domino(int leftValue, int rightValue) {
       this.leftValue = leftValue;
       this.rightValue = rightValue;
   }

   public int getLeftValue() {
       return leftValue;
   }

   public int getRightValue() {
       return rightValue;
   }

   public static void main(String[] args) {

       // This creates the Array
       Domino[] dominos = new Domino[] {
               new Domino(2, 3),
               new Domino(3, 2),
               new Domino(2, 5),
               new Domino(2, 5) };
       // This part Loops and matchs left and right values
       Domino previous = null;

       for (Domino current : dominos) {
           if (previous != null) {
               if (current.getLeftValue() != previous.getRightValue()) {
                   try {
                       throw new Exception(\"Illegal\");
                   } catch (Exception e) {
                       e.printStackTrace();
                   }
              
               }
           }
           previous = current;
       }
   }
}

____________________

public class Domino { private int leftValue; private int rightValue; public Domino(int leftValue, int rightValue) { this.leftValue = leftValue; this.rightValue
public class Domino { private int leftValue; private int rightValue; public Domino(int leftValue, int rightValue) { this.leftValue = leftValue; this.rightValue

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site