Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / December 2004

Tip: Looking for answers? Try searching our database.

Need Help getting kinks out

Thread view: 
CappaKia - 13 Dec 2004 17:13 GMT
I'm almost finished with my project but I am getting error messages when I
compile.  Can you help??

Here are the error messages that I am getting:
\My Documents\CS151\TicketDriver.java:121: '}' expected
}//end class TicketDriver
 ^
\Ticket.java:83: ')' expected
     (Character.toUpperCase(this.response)==
(Character.toUpperCase(otherTicket.response))
                                                                         
               ^
\Ticket.java:90: ')' expected
 }
  ^
\Ticket.java:91: illegal start of expression
}//end equals
^
4 errors

Tool completed with exit code 1

Here is a copy of my program:

* This class inputs the speeders info, calculates and
* outputs.
*
********************************************************************************************/
import java.text.DecimalFormat;

public class Ticket
{
public String name;                //Input driver's name
private int speed;                    //Input driver's speed
private int speedLimit;            //Input of speed limit
private double fine;                //Calculates fine Amount
private char response;               //Input of whether driving in school zone

//********************************************************************************************
//This constructor assigns values into insatnce variables

public Ticket(String name, int speed, int speedLimit, char response)
{
  this.name = name;
  this.speed = speed;
  this.speedLimit = speedLimit;
  this.response = response;
} // end Ticket constructor

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

public Ticket (String name, int speedLimit)
{
 this.name = name;
 this.speedLimit = speedLimit;

}//end Ticket constructor
//********************************************************************************************
//This method inputs

 public Ticket()
{
 System.out.print("Enter driver's name: ");
 name = Input.readLine ();
 System.out.print("Enter driver's speed: ");
 speed = Input.readInt ();
 while (speed > 100)
  {
       System.out.println("Number of hours illegal");
       System.out.print("Please enter correct number of hours:");
       speed = Input.readInt();
  }
 System.out.print("Was driver in school zone during school hours? Y or N:
");
 response = Input.readChar ();
 System.out.print("Enter speed limit: ");
 speedLimit = Input.readInt ();
}//end Drivers Information

//********************************************************************************************
//Make Copy

public Ticket makeCopy()
{

 Ticket ticket = new Ticket();
 ticket.name = this.name;
 ticket.speed = this.speed;
 ticket.speedLimit = this.speedLimit;
 ticket.response = this.response;
 return ticket;
} // end makeCopy

//*********************************************************************************************
//This method checks to see if any of the car drivers have the same
information

 public boolean equals (Ticket otherTicket)
{

 if  ((this.name.equalsIgnoreCase(otherTicket.name)) &&
     (this.speed == (otherTicket.speed))&&
     (this.speedLimit == (otherTicket.speedLimit)) &&
     (Character.toUpperCase(this.response)==
(Character.toUpperCase(otherTicket.response))
 {
     return true;
 }
 else
 {
    return false;
 }
}//end equals

//***********************************************************************************************
//This method calculates the fine

public void fine()
{
  int overSpeed;

  overSpeed = speed - speedLimit;

  if(overSpeed > 10)
  {
    fine = overSpeed * 10;
  }
  else
  {
    fine = overSpeed * 6;
  }
}// end Calculate Fine

//*********************************************************************************************
//This method is the input validation

public void schoolZone ()
{

 if(response == 'y' || response == 'Y')
 {
   fine = fine * 2;
 }
 //else
 //{
 // System.out.println("Invalid Entry");
 // System.out.println("You entered" + response +"Please enter a Y for
Yes or N for No: ");
 //}
}//end school zone
//********************************************************************************************
//This method prints the table heading

public void tableHeading ()
{
 System.out.println("Name" + '\t'+'\t' + "Speed" + '\t' + "SpeedLimit" +
'\t' + "SchoolZone" +
 '\t' + "Fine");

}// end tableheading

//********************************************************************************************
//This method prints the output

public void tableData ()
{

 DecimalFormat currencyFormat = new DecimalFormat ("$, ##0.00");

 System.out.println(name + '\t'+"   " + speed + '\t' + speedLimit + '\t'
+ '\t' + response + '\t' +
 '\t' + currencyFormat.format(fine));

}// end tableData

//*******************************************************************************************
//This method returns the name of the driver

 public String getName()
 {
    return name;

 } //end getName

//******************************************************************************************
//This method returns the speed

 public int getSpeed()
 {
    return speed;

 } //end getSpeed

//******************************************************************************************
//This method returns the speed limit

 public int getSpeedLimit()
 {
    return speedLimit;

 } // end getSpeedLimit

//******************************************************************************************
//This method returns the response

 public char getResponse()
  {
     return response;

  } // end getresponse

//******************************************************************************************
//This method returns the fine

   public double getFine()
 {
   return fine;

 } // end getfine

//******************************************************************************************
//This method changes the name

public void setName(String dName)
{
  name = dName;

} //end setName
//********************************************************************************************
//This method changes the speed

public void setSpeed(int dSpeed)
{
  speed = dSpeed;

} //end setSpeed

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

//This method changes the speed limit

 public void setSpeedLimit(int cSpeedLimit)
 {
   speedLimit = cSpeedLimit;

 } //end setspeedLimit

//********************************************************************************************
//This method changes the response

 public void setResponse(char cResponse)
 {
   response = cResponse;

 } //end setresponse

//*********************************************************************************************
// This method changes all of the variables

public void setALL(String dName, int dSpeed, int cSpeedLimit, char
cResponse)
{
    name = dName;
    speed = dSpeed;
    speedLimit = cSpeedLimit;
    response = cResponse;

}//end SetALL
}//end class Ticket

//**********************************************************************************************
Sebastian Scheid - 13 Dec 2004 18:07 GMT
> I'm almost finished with my project but I am getting error messages when I
> compile.  Can you help??

The compiler presents the line with the error. So please have a look at
these lines before posting lots of code!
Some given lines may not contain errors. Often the compiler is confused by
missing paranthesis.

> Here are the error messages that I am getting:
> \My Documents\CS151\TicketDriver.java:121: '}' expected
[quoted text clipped - 3 lines]
>      (Character.toUpperCase(this.response)==
> (Character.toUpperCase(otherTicket.response))

Ok, let's have a look at line 83.

>                ^
> \Ticket.java:90: ')' expected
[quoted text clipped - 8 lines]
>
> Here is a copy of my program:

[snip]

> //*********************************************************************************************
> //This method checks to see if any of the car drivers have the same
[quoted text clipped - 16 lines]
>  }
> }//end equals

There are may superflous parentheses in this conditional statement. This
does not only confuse the compiler but readers (and the author) too. I think
you should delete the paranthesis before the last "Character" and add one
after "otherTicket.response))":

if  ((this.name.equalsIgnoreCase(otherTicket.name)) &&
    (this.speed == (otherTicket.speed))&&
    (this.speedLimit == (otherTicket.speedLimit)) &&
    (Character.toUpperCase(this.response)==
     Character.toUpperCase(otherTicket.response)))
{

I hope this works.

btw I prefer:

public boolean equals (Ticket otherTicket) {
   return this.name.equalsIgnoreCase(otherTicket.name) &&
       this.speed == (otherTicket.speed)&&
       this.speedLimit == (otherTicket.speedLimit) &&
       Character.toUpperCase(this.response)==Character.toUpperCase(otherTicket.response);
}

Perhaps there are more errors in the rest of the code.

Regards
Sebastian


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.