Re: Need help figuring out errors in program
From: CappaKia (cappakia_at_nospam.com)
Date: 12/05/04
- Next message: Ryan Stewart: "Re: Accessing a method in an object that is in a vector. (2nd Try)"
- Previous message: Nicholas Parnell: "Re: Accessing a method in an object that is in a vector. (2nd Try)"
- In reply to: Ryan Stewart: "Re: Need help figuring out errors in program"
- Next in thread: Starshine Moonbeam: "Re: Need help figuring out errors in program"
- Reply: Starshine Moonbeam: "Re: Need help figuring out errors in program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 04 Dec 2004 20:12:28 -0500
This is a copy of my class.
* This class inputs the speeders info, calculates and
* outputs results.
*
********************************************************************************************/
public class Ticket
{
private String name; //Driver's name
private int speed; //Driver's speed
private int speedLimit;
private double fine; //Fine Amount
private char response; //Driving in school zone
//********************************************************************************************
//This method inputs the Drivers Information
public void ticketInfo()
{
System.out.print("Enter driver's name: ");
name = Input.readLine ();
System.out.print("Enter driver's speed: ");
speed = Input.readInt ();
while (speed > 200)
{
System.out.println("Number of hours illegal");
System.out.println("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
//********************************************************************************************
//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 ()
{
System.out.println(name + '\t'+" " + speed + '\t' + speedLimit + '\t'
+ '\t' + response + '\t' +
'\t' + 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 char getFine()
{
return fine;
} // end getfine
//***********************************************************************************************
//This method changes the name
public void setName(String dName)
{
this.name = dName;
} //end setName
//**********************************************************************************************
//This method changes the speed
public void setSpeed(int dSpeed)
{
this.speed = dSpeed;
} //end setSpeed
//***********************************************************************************************
//This method changes the speed limit
public void setspeedLimit(int cSpeedLimit)
{
this.speedLimit = cSpeedLimit;
} //end setspeedLimit
//***********************************************************************************************
//This method changes the response
public void setresponse(char cResponse)
{
this.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 class Ticket
//**************************************************************************************************
- Next message: Ryan Stewart: "Re: Accessing a method in an object that is in a vector. (2nd Try)"
- Previous message: Nicholas Parnell: "Re: Accessing a method in an object that is in a vector. (2nd Try)"
- In reply to: Ryan Stewart: "Re: Need help figuring out errors in program"
- Next in thread: Starshine Moonbeam: "Re: Need help figuring out errors in program"
- Reply: Starshine Moonbeam: "Re: Need help figuring out errors in program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|