Hi, I am trying to fix some issues in my java code. The whole code is written by
ID: 3561476 • Letter: H
Question
Hi,
I am trying to fix some issues in my java code. The whole code is written by our teacher and we are supposed to add our code to a part it. Here is what we are supposed to do:
This is a Ticket class, and is already written by out teacher. We are supposed to add our codes to fight for this ticket based on this information:
You will be given a ticket ID number, the legal name of the person who received the ticket, and a java Ticket class. Your job will be to create an instance of the Ticket class using the ticket ID number, and then to query that Ticket to determine if one of the following four valid reasons for dismissing the ticket exist:
Explanation / Answer
Ticket myTicket = new Ticket(ticketID);
boolean isTicketValid = IsTicketValid(legalName, myTicket);
if(isTicketValid)
{
System.out.println("Ticket is valid");
}
else
{
System.out.println("Ticket is invalid");
}
---------------------------------------------------------------------------------------------------------------------------------------------
boolean IsTicketValid(String legalName, Ticket ticket)
{
if(!(ticket.getName().equalsIgnoreCase(legalName)))
{
return false;
}
else if(ticket.getSpeed() < (ticket.getSpeedLimit() + 11))
{
return false;
}
else if((ticket.getCameraID().charAt(0) == 'A') || (ticket.getCameraID().charAt(0) == 'a'))
{
return false;
}
else if((ticket.getCameraID().substring(ticket.getCameraID().length()-2,ticket.getCameraID().length()-1)).equals("35"))
{
return false;
}
else if((ticket.getLocation().toLowerCase().indexOf("59th ave") != -1) || (ticket.getLocation().indexOf("olive") != -1))
{
return false;
}
else
{
return true;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.