Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting IF statements - Java
    primarykey
    data
    text
    <p>I keep coming across this problem, where i want to insert an IF statement into my class, but keeps returning an illegal start of type/expression error.</p> <p>Is there something im doing wrong here, if so could somebody point me in the direction of where i should be puting these IF statements.</p> <p>I need an IF statement like:</p> <pre><code>IF (RList.contains(r1.getRouteName() == "Route2")) c1.setCollision1(b1.getStartTime ++ c1.getCollision1) ELSE c1.setCollision2(b1.getStartTime ++ c1.getCollision2) </code></pre> <p>I know that is more than likely wrong, but anyway. I want to insert that piece of code into the following class</p> <pre><code>import javax.swing.*; import java.sql.*; import java.util.*; public class Main { public static void main(String[] args) { Student s2 = new Student(); Booking b1 = new Booking(); Route r1 = new Route(); Route r2 = new Route(); Examiner e1 = new Examiner(); Examiner e2 = new Examiner(); Collision c1 = new Collision(); //New Student s2.setStudentId(Integer.parseInt(JOptionPane.showInputDialog("Enter ID for Student 2: [0001]"))); s2.setFname(JOptionPane.showInputDialog("Enter first name of Student 2: ")); s2.setLname(JOptionPane.showInputDialog("Enter last name of Student 2: ")); s2.setAddress(JOptionPane.showInputDialog("Enter address for Student 2: ")); s2.setPhoneNo(JOptionPane.showInputDialog("Enter phone number for Student 2: ")); s2.setOtherDetails(JOptionPane.showInputDialog("Enter other details for Student 2: ")); JOptionPane.showMessageDialog(null,"Student Two: \n" + s2.toString()); //End of New Student //New Booking b1.setBookingId(Integer.parseInt(JOptionPane.showInputDialog("Enter ID for Booking 1: [0001]"))); b1.setBookingType(JOptionPane.showInputDialog("Enter Booking Type for Booking 1: [Exam or Lesson]")); b1.setStartTime(Double.parseDouble(JOptionPane.showInputDialog("EnterStart time for Booking 1: "))); b1.setEndTime(Double.parseDouble(JOptionPane.showInputDialog("Enter address for Student 2: "))); b1.setBookingDate(JOptionPane.showInputDialog("Enter Date for Booking 1: [01-JAN-2012]")); b1.setHistory(JOptionPane.showInputDialog("Enter name of previous examiner 2: [enter 'null' if no previous]")); JOptionPane.showMessageDialog(null,"Booking One: \n" + b1.toString()); //End of New Booking //Set the Routes r1.setRouteId(0001); r1.setRouteName("Route1"); r1.setEndTime(0.40); r2.setRouteId(0002); r2.setRouteName("Route2"); r2.setEndTime(0.50); //End Set Routes //Create Examiners e1.setExaminerId(0001); e1.setName("John Murphy"); e1.setOtherDetails("ADI Registered"); e2.setExaminerId(0002); e2.setName("Lucy Casey"); e2.setOtherDetails("ADI Registered"); //End Create Examiners // &lt;editor-fold defaultstate="collapsed" desc="Connect to database and insert data into database"&gt; String strConn = "jdbc:oracle:thin:@oracle.staff.ittralee.ie:1521:orcl"; String strUser = "*"; String strPassword = "*"; try { Driver drv = new oracle.jdbc.driver.OracleDriver(); DriverManager.registerDriver(drv); Connection conn = DriverManager.getConnection(strConn, strUser, strPassword); //code to execute commands... // &lt;/editor-fold&gt; //StudentInsert String query = "INSERT INTO Student(STUDENTID, FNAME, LNAME, ADDRESS, " + "PHONENO, OTHERDETAILS) VALUES (?, ?, ?, ?, ?, ?)"; PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setInt(1, s2.getStudentId()); pstmt.setString(2, s2.getFname()); pstmt.setString(3, s2.getLname()); pstmt.setString(4, s2.getAddress()); pstmt.setString(5, s2.getPhoneNo()); pstmt.setString(6, s2.getOtherDetails()); pstmt.executeUpdate(); //End Student Insert //Booking Insert String query1 = "INSERT INTO Booking(BOOKINGID, BOOKINGTYPE, LNAME, STARTTIME, ENDTIME, " + "BOOKINGDATE, HISTORY) VALUES (?, ?, ?, ?, ?, ?)"; PreparedStatement pstmt1 = conn.prepareStatement(query1); pstmt1.setInt(1, b1.getBookingId()); pstmt1.setString(2, b1.getBookingType()); pstmt1.setDouble(3, b1.getStartTime()); pstmt1.setDouble(4, b1.getEndTime()); pstmt1.setString(5, b1.getBookingDate()); pstmt1.setString(6, b1.getHistory()); pstmt1.executeUpdate(); //End Booking Insert //Returns Id of route not in use String query2 = "SELECT R.RouteID FROM Route R WHERE RouteID not in (SELECT B.RouteId FROM Booking B)"; JOptionPane.showMessageDialog(null, query2); //End Route not in use //Adding routes to a list to randomly assign an examiner to a route LinkedList&lt; String&gt; EList = new LinkedList&lt; String&gt;(); EList.add(e1.getName()); EList.add(e2.getName()); Collections.shuffle(EList); LinkedList&lt; String&gt; RList = new LinkedList&lt; String&gt;(); RList.add(r1.getRouteName()); RList.add(r2.getRouteName()); Collections.shuffle(RList); JOptionPane.showMessageDialog(null, "Examiner: " + EList + "\nRoute: " + RList); //End random assign route } catch(SQLException e) { System.out.println(" A SQL error: " + e.getMessage()); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload