This is code Can you make this code to GUI version plz im

This is code ////// //////////////////////////// Can you make this code to GUI version plz

////////////////////////////////////////////////

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import javax.swing.JFileChooser;

public class HexagonMain {
   static Hexagon[] places = new Hexagon[7];
   static Set solution = new HashSet(); // Set to store solutions. Set will avoid duplicate solutions

   public static void main(String[] args) {
       Hexagon[] hexagons = new Hexagon[7];
       JFileChooser jFileChooser = new JFileChooser();
       jFileChooser.showOpenDialog(null); //prompts user to select file
       File file = jFileChooser.getSelectedFile();
       if (file != null) {
           try {
               FileReader fr = new FileReader(file);
               BufferedReader br = new BufferedReader(fr);
               String input = null;
               int index = 0;
               while ((input = br.readLine()) != null && index < 7) { //Read from file
                   String[] values = input.split(\" \");
                   hexagons[index++] = new Hexagon(values[1]); //Construct hexagon objects from input data
               }
               br.close();
           } catch (FileNotFoundException e) {
               e.printStackTrace();
           } catch (IOException e) {
               e.printStackTrace();
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
       arrange(hexagons, 0); // call method to place the hexagons
       if (solution.isEmpty()) {
           System.out.println(\"No Solutions found\");
       } else {
           int i = 0;
           for(String str:solution){
               System.out.println(\"Solution Number\" + ++i + \"\ \" + str);
           }
       }

   }

   //method to arrange hexagons, inputs are hexagons and first position to place the hexagon
   public static void arrange(Hexagon[] hexagons, int start) {
       if (start < places.length) {
           for (int i = 0; i < hexagons.length; i++) {
               if (hexagons[i].position == -1) { //find out unused hexagons
                   places[start] = hexagons[i]; //place hexagon in position
                   hexagons[i].position = start; // save the position in hexagon object also
                   if (checkValid()) { //Checks if placement is valid
                       arrange(hexagons, start + 1); //proceeds to place next hexagon
                   }
                   for (int j = 0; j < 5; j++) {
                       hexagons[i].rotate(); //Rotate the current hexagon
                       if (checkValid()) {
                           arrange(hexagons, start + 1);
                       }
                   }
                   hexagons[i].rotate(); //Reset back to initial position
                   places[start] = null; //Remove hexagon from position
                   hexagons[i].position = -1;
               }
           }
       } else {
           if (checkValid()) { //Check to see if final result is valid
               StringBuilder str = new StringBuilder();
               for (Hexagon hex : places) {
                   str.append(hex.toString() + \"\ \");
               }
               solution.add(str.toString()); // Save solution to a set
           }
       }
   }

   //Method to check if any every placement is valid
   public static boolean checkValid() {

       for (int i = 0; i <= 5; i++) {
           if (places[i + 1] != null
                   && places[0].section[i] != places[i + 1].section[(i + 3) % 6]) //comparison based on center hexagon
               return false;
           if (places[i + 1] != null
                   && places[((i + 1) % 6) + 1] != null
                   && places[i + 1].section[(i + 2) % 6] != places[((i + 1) % 6) + 1].section[(i + 5) % 6]) { //comparison of outer hexagons with each other
               return false;
           }
       }
       return true;
   }

}

File: Hexagon.java


public class Hexagon {
  
   char[] section;
   int position = -1;
  
   public Hexagon(String colorString){ //constructor
       section = colorString.toCharArray();
   }
  
   //Method to rotate hexagon
   public void rotate(){
       char temp = section[0];
       for(int i=1;i            section[i-1] = section[i];
       }
       section[section.length -1] = temp;
   }

   @Override
   public String toString() {
       return \"Position \" + (position + 1) + \": \" + new String(section);
   }
  

}

//////////////////////////////////////////////////////////////////////////////////////////////////

3

Solution

Hi, In the above code \"Method to rotate hexagon\" is incomplete with errors.

public void rotate(){
       char temp = section[0];
       for(int i=1;i            section[i-1] = section[i];
       }

       section[section.length -1] = temp;
   }

java:106: error: \';\' expected
for(int i=1;i section[i-1] = section[i];
^

This is code ////// //////////////////////////// Can you make this code to GUI version plz //////////////////////////////////////////////// import java.io.Buffe
This is code ////// //////////////////////////// Can you make this code to GUI version plz //////////////////////////////////////////////// import java.io.Buffe
This is code ////// //////////////////////////// Can you make this code to GUI version plz //////////////////////////////////////////////// import java.io.Buffe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site