Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7635747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:30:15+00:00 2026-05-31T07:30:15+00:00

I keep coming across this problem, where i want to insert an IF statement

  • 0

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.

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.

I need an IF statement like:

IF (RList.contains(r1.getRouteName() == "Route2"))
c1.setCollision1(b1.getStartTime ++ c1.getCollision1)

ELSE
c1.setCollision2(b1.getStartTime ++ c1.getCollision2)

I know that is more than likely wrong, but anyway.
I want to insert that piece of code into the following class

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

 // <editor-fold defaultstate="collapsed" desc="Connect to database and insert data into database">


       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... 

// </editor-fold>

        //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< String> EList = new LinkedList< String>();

        EList.add(e1.getName());
        EList.add(e2.getName());
        Collections.shuffle(EList);

        LinkedList< String> RList = new LinkedList< String>();

        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());
    }





    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:30:16+00:00Added an answer on May 31, 2026 at 7:30 am

    This code is wrong

    IF (RList.contains(r1.getRouteName() == "Route2"))
    c1.setCollision1(b1.getStartTime ++ c1.getCollision1)
    
    ELSE
    c1.setCollision2(b1.getStartTime ++ c1.getCollision2)
    

    It should look like this

    if (RList.contains(r1.getRouteName() == "Route2")) {
        c1.setCollision1(b1.getStartTime + c1.getCollision1);
    }
    else {
        c1.setCollision2(b1.getStartTime + c1.getCollision2);
    }
    

    Also

    RList.contains(r1.getRouteName() == "Route2")

    won’t work the way you want it to. First off Strings should be compared using equals rather than == as in

    r1.getRouteName().equals("Route2").

    Secondly what this will do if check if RList contains the value true or false depending on the result of the r1.getRouteName().equals("Route2"). I think this might actually cause an compiler error.

    If you want to determine whether RList includes r1 and r1’s Route name is Route2 you’ll have to do this.

    if(RList.contains(r1) && r1.getRouteName().equals("Route2"))
    

    Note this will compare with case sensitivity on for case insensitivity use equalsIgnoreCase() instead of equals

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been studying class inheritance recently and I keep coming across this specific piece
So, one problem pattern that I keep coming across and don't have a good
I keep coming across the use of this word and I never understand its
I'm learning javascript. Poked around this excellent site to gather intel. Keep coming across
This is an issue I seem to keep coming across. If for example I
I'm using XMLSerializer to write xml but i keep coming across an exception that
I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
Keep getting this error after inserting a subdatasheet into a query and trying to
I keep running across this loading image http://georgia.ubuntuforums.com/images/misc/lightbox_progress.gif which seems to have entered into
I keep coming across techniques like the code below where i need to filter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.