WHY DO I GET ERRORS FOR loadTicket MEthod saying incompatiable type, please someone tell me whats wrong and tell me the correction for it?

import java.util.Date;

import java.lang.*;

import java.io.*;

import java.util.Calendar;



public class Ticket {

    public TicketInfo x;

    public int tNumber;

    public static long entranceTime;

    public static long paymentTime;

    public static String ticketStatus;

    public static double balance;

    /********************************************************************************************/

    public String createTicket(){



    tNumber = (int)(Math.random() * 999999)+100000;

    /*public int generateTicketNumber(){

        this.tNumber = (int)(Math.random() * 999999)+100000;

    }*/





        File dir = new File("Ticket");

        boolean exists = dir.exists();

        if (!exists){

            dir.mkdir();

        } // end if



        TicketInfo x = new TicketInfo(entranceTime, paymentTime, ticketStatus, balance);







        String fileName = "Ticket/"+tNumber+".dat";

        File ticket = new File(fileName);



        if(ticket.exists()){

            //generateTicketNumber();

            return "Try again";

        }

        else {

            try{

                FileWriter fileWriter = new FileWriter(fileName);

                BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

                bufferedWriter.write(x.toString());

                bufferedWriter.close();

                fileWriter.close();



                return "A Ticket is Created...Please take your ticket "+ tNumber;

            }

            catch(IOException e){

                return "Sorry, ticket generation currently unavailable. Please call for assistance?";

            }

        }



        public loadTicket(int tNumber){

            String fileName2 = "Ticket/"+tNumber+".dat";

            File ticket2 = new File(fileName2);

            if(ticket2.exists()){

                try{

                    FileReader fileReader = new FileReader(fileName2);

                    BufferedReader bufferedReader = new BufferedReader(fileReader);

                    entranceTime = bufferedReader.readLine();

                    paymentTime = bufferedReader.readLine();

                    ticketStatus = bufferedReader.readLine();

                    balance = bufferedReader.readLine();

                    bufferedReader.close();

                    fileReader.close();

                    return "The Ticket has loaded successfully.";

                }

                catch(IOException e){

                    /**entranceTime = "";

                    paymentTime = "";

                    ticketStatus = "";

                    balance ="";*/

                    return "The Ticket could not be read.";

                }           

            }

            else {

                /*entranceTime = "";

                paymentTime = "";

                ticketStatus = "";

                balance ="";*/

                return "This Ticket hasn't been registered.";

            }







        }













    }







}//end class Ticket

what does your error message say? the entire message?

what does your error message say? the entire message?

Ticket.java:54: illegal start of expression
                public loadTicket(int tNumber){
                ^
Ticket.java:54: '.class' expected
                public loadTicket(int tNumber){
                                      ^
Ticket.java:54: ';' expected
                public loadTicket(int tNumber){
                                             ^
3 errors

C:\Users\Mahady\Desktop\Java 14122011>javac PaymentNewGUI.java
.\Ticket.java:54: illegal start of expression
                public loadTicket(int tNumber){
                ^
.\Ticket.java:54: '.class' expected
                public loadTicket(int tNumber){
                                      ^
.\Ticket.java:54: ';' expected
                public loadTicket(int tNumber){
                                             ^
PaymentNewGUI.java:53: cannot find symbol
symbol  : method loadTicket(int)
location: class Ticket
                        String loadMessage = ticket.loadTicket(ticketIDNumber);
                                                   ^
.\Ticket.java:54: unexpected type
required: value
found   : class
                public loadTicket(int tNumber){
                                  ^
.\Ticket.java:61: incompatible types
found   : java.lang.String
required: long
                                        entranceTime = bufferedReader.readLine()
;
                                                                              ^
.\Ticket.java:62: incompatible types
found   : java.lang.String
required: long
                                        paymentTime = bufferedReader.readLine();

                                                                             ^
.\Ticket.java:64: incompatible types
found   : java.lang.String
required: double
                                        balance = bufferedReader.readLine();
                                                                         ^
8 errors

you need to be more carefull where you place your brackets. you are writing methods within methods.

also, method declarations like this:

public loadTicket(int tNumber){

are wrong. it's not a constructor, so you should provide a return type. in the case of this method (if I've read your code well, but I just glanced at it), you'll need:

public String loadTicket(int tNumber){

try and fix these errors, that might also give you a clue about the other errors. read the error messages closely, they tell you what kind of error has occured, and where in your code the error occured, so the most of the issues should be easy to fix.

you need to be more carefull where you place your brackets. you are writing methods within methods.

also, method declarations like this:

public loadTicket(int tNumber){

are wrong. it's not a constructor, so you should provide a return type. in the case of this method (if I've read your code well, but I just glanced at it), you'll need:

public String loadTicket(int tNumber){

try and fix these errors, that might also give you a clue about the other errors. read the error messages closely, they tell you what kind of error has occured, and where in your code the error occured, so the most of the issues should be easy to fix.

.\Ticket.java:54: illegal start of expression
public String loadTicket(int tNumber){
^
.\Ticket.java:54: ';' expected
public String loadTicket(int tNumber){
^
.\Ticket.java:54: ';' expected
public String loadTicket(int tNumber){
^
PaymentNewGUI.java:53: cannot find symbol
symbol : method loadTicket(int)
location: class Ticket
String loadMessage = ticket.loadTicket(ticketIDNumber);
^
.\Ticket.java:61: incompatible types
found : java.lang.String
required: long
entranceTime = bufferedReader.readLine()
;
^
.\Ticket.java:62: incompatible types
found : java.lang.String
required: long
paymentTime = bufferedReader.readLine();

^
.\Ticket.java:64: incompatible types
found : java.lang.String
required: double
balance = bufferedReader.readLine();
^
7 errors

Post your current code so we can see what you've done so far

and, as I said, check the position of your brackets. since most of the errors are still the same, I assume you are still writing methods within other methods.

and for your last error, cast your String object to a double =>
double.parseDouble(...);

import java.util.Date;

import java.lang.*;

import java.io.*;

import java.util.Calendar;



public class Ticket {

    public TicketInfo x;

    public int tNumber;

    public static long entranceTime;

    public static long paymentTime;

    public static String ticketStatus;

    public static double balance;

    /********************************************************************************************/

    public String createTicket(){



    tNumber = (int)(Math.random() * 999999)+100000;

    /*public int generateTicketNumber(){

        this.tNumber = (int)(Math.random() * 999999)+100000;

    }*/





        File dir = new File("Ticket");

        boolean exists = dir.exists();

        if (!exists){

            dir.mkdir();

        } // end if



        TicketInfo x = new TicketInfo(entranceTime, paymentTime, ticketStatus, balance);







        String fileName = "Ticket/"+tNumber+".dat";

        File ticket = new File(fileName);



        if(ticket.exists()){

            //generateTicketNumber();

            return "Try again";

        }

        else {

            try{

                FileWriter fileWriter = new FileWriter(fileName);

                BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

                bufferedWriter.write(x.toString());

                bufferedWriter.close();

                fileWriter.close();



                return "A Ticket is Created...Please take your ticket "+ tNumber;

            }

            catch(IOException e){

                return "Sorry, ticket generation currently unavailable. Please call for assistance?";

            }

        }



        public  String loadTicket(int tNumber){

            String fileName2 = "Ticket/"+tNumber+".dat";

            File ticket2 = new File(fileName2);

            if(ticket2.exists()){

                try{

                    FileReader fileReader = new FileReader(fileName2);

                    BufferedReader bufferedReader = new BufferedReader(fileReader);

                    entranceTime = bufferedReader.readLine();

                    paymentTime = bufferedReader.readLine();

                    ticketStatus = bufferedReader.readLine();

                    balance = bufferedReader.readLine();

                    bufferedReader.close();

                    fileReader.close();

                    return "The Ticket has loaded successfully.";

                }

                catch(IOException e){

                    /**entranceTime = "";

                    paymentTime = "";

                    ticketStatus = "";

                    balance ="";*/

                    return "The Ticket could not be read.";

                }           

            }

            else {

                /*entranceTime = "";

                paymentTime = "";

                ticketStatus = "";

                balance ="";*/

                return "This Ticket hasn't been registered.";

            }

        }
    }
}//end class Ticket

and, as I said, check the position of your brackets. since most of the errors are still the same, I assume you are still writing methods within other methods.

and for your last error, cast your String object to a double =>
double.parseDouble(...);

The error has reduced to 6 but still there are some issues, please check btw thanks for your time

Ticket.java:56: ';' expected
                public  String loadTicket(int tNumber){
                                                     ^
Ticket.java:66: class expected
                                        balance = double.parseDouble(bufferedRea
der.readLine());
                                                         ^
Ticket.java:66: ';' expected
                                        balance = double.parseDouble(bufferedRea
der.readLine());
                                                                    ^
Ticket.java:66: ';' expected
                                        balance = double.parseDouble(bufferedRea
der.readLine());

              ^

Still some error but reduced to 6 from 7 please check if you have time

Ticket.java:56: illegal start of expression
                public  String loadTicket(int tNumber){
                ^
Ticket.java:56: ';' expected
                public  String loadTicket(int tNumber){
                                         ^
Ticket.java:56: ';' expected
                public  String loadTicket(int tNumber){
                                                     ^
Ticket.java:66: class expected
                                        balance = double.parseDouble(bufferedRea
der.readLine());
                                                         ^
Ticket.java:66: ';' expected
                                        balance = double.parseDouble(bufferedRea
der.readLine());
                                                                    ^
Ticket.java:66: ';' expected
                                        balance = double.parseDouble(bufferedRea
der.readLine());

              ^
import java.util.Date;

import java.lang.*;

import java.io.*;

import java.util.Calendar;



public class Ticket {

	public TicketInfo x;

	public int tNumber;

	public static long entranceTime;

	public static long paymentTime;

	public static String ticketStatus;

	public static double balance;

	/********************************************************************************************/

	public String createTicket(){

		

	tNumber = (int)(Math.random() * 999999)+100000;

	/*public int generateTicketNumber(){

		this.tNumber = (int)(Math.random() * 999999)+100000;

	}*/



	

		File dir = new File("Ticket");

		boolean exists = dir.exists();

		if (!exists){

			dir.mkdir();

		} // end if



		TicketInfo x = new TicketInfo(entranceTime, paymentTime, ticketStatus, balance);

		 

   



		String fileName = "Ticket/"+tNumber+".dat";

		File ticket = new File(fileName);

		

		if(ticket.exists()){

			//generateTicketNumber();

			return "Try again";

		}

		else {

			try{

				FileWriter fileWriter = new FileWriter(fileName);

				BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

				bufferedWriter.write(x.toString());

				bufferedWriter.close();

				fileWriter.close();

				

				return "A Ticket is Created...Please take your ticket "+ tNumber;
				System.out.println("WANKER!");

			}

			catch(IOException e){

				return "Sorry, ticket generation currently unavailable. Please call for assistance?";
				

			}

		}

		

		public  String loadTicket(int tNumber){

			String fileName2 = "Ticket/"+tNumber+".dat";

			File ticket2 = new File(fileName2);

			if(ticket2.exists()){

				try{

					FileReader fileReader = new FileReader(fileName2);

					BufferedReader bufferedReader = new BufferedReader(fileReader);

					entranceTime = bufferedReader.readLine();

					paymentTime = bufferedReader.readLine();

					ticketStatus = bufferedReader.readLine();

					balance = double.parseDouble(bufferedReader.readLine());

					bufferedReader.close();

					fileReader.close();

					return "The Ticket has loaded successfully.";

				}

				catch(IOException e){

					/**entranceTime = "";

					paymentTime = "";

					ticketStatus = "";

					balance ="";*/

					return "The Ticket could not be read.";

				}			

			}

			else {

				/*entranceTime = "";

				paymentTime = "";

				ticketStatus = "";

				balance ="";*/

				return "This Ticket hasn't been registered.";

			}

		

		

		

		}

		

		

		

		

		



	}

	

	

	

}//end class Ticket

your initializing public String loadTicket(int tNumber) method inside public String createTicket()... your missing a bracket

also the lines where the errors are found does not match your posted code

your initializing public String loadTicket(int tNumber) method inside public String createTicket()... your missing a bracket

also the lines where the errors are found does not match your posted code

thanks that really helped. :)

thanks that really helped. :)

I already told you this in my first reply.
did this really help, or did you just now start to read the answers you're getting?

commented: haha...original answer credit goes to you really...happy now :P +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.