wood burning stoves 2.0*
The moose likes Java in General and the fly likes Desperately need help writing Tester Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Desperately need help writing Tester" Watch "Desperately need help writing Tester" New topic
Author

Desperately need help writing Tester

Amaad Isam
Greenhorn

Joined: Oct 30, 2008
Posts: 3
hi, i have written out an entire program and have compiled it. so i know that the entire program runs without any mistakes. however i am having some difficulty making the tester. any help at all will be appreciated.

the program that i have written is below. under that i will put what is my stab at a tester. however, i think that my tester is completely wrong. if any one can show me how to do the tester for this program that would be great. i have done testers before but never for programs with if else statements.


the program i have written and know works:

// Creates a car that has variables that can be changed such as gastank capacity, distance traveled, and fuel effficiency
public class Car
{
public static final double GALLON_VALUE = 1;
public static final double MILE_VALUE = 1;



private String name;
private double milesPerGallon;// fuel efficiency of the car
private double capacity;
private double distance;// distance already travelled in miles
private double gasAvailable;
private double emptySpace;
/**
Constructs a car with default charachteristics.
*/
public Car()
{
name = "defaultCar";
capacity = 20.0;
distance = 0.0;
milesPerGallon = 40.0;
}

/**
Constructs a car with the following: name, Fuel Efficiency, tank Capacity, Distance Traveled and available gas.
*/
void Car(String customName,double customfueleff, double tankCapacity ) {
name =customName;
milesPerGallon = customfueleff;
capacity = tankCapacity;
distance = 0.0;
emptySpace = capacity;
gasAvailable = 0.0; //should depend on car
}

/**
Adds a specified amount of gas n gallons relative to the tank Capacity
*/

public boolean addGas(double gallons){

emptySpace = capacity - gasAvailable;

if (emptySpace <=0 )
return false;
else if(gallons > emptySpace ) {
gasAvailable =gasAvailable +emptySpace;
return true;
}
else{
gasAvailable= gasAvailable +gallons;
return true;
}
}

/**
drives a specified distance proportinate to amount of gas available
*/

public boolean drive(double requestedDistance) {

double possibleDistance = (gasAvailable*milesPerGallon);
if (requestedDistance < 0) {
return false; }
if (requestedDistance <= possibleDistance) {
distance += requestedDistance;
gasAvailable-=(requestedDistance/milesPerGallon);
return true;
}
else { return false; }
}



/**
Returns the name of the current car as a String
*/
public String getName()
{
return ("The name of the car is "+ name);
}
/**
Returns the fuel efficiency of the current car in miles per gallon
*/
public double getEfficiency()
{
return milesPerGallon;
}

/**
returns the gas tank capacity of the current car in gallons
*/
public double getCapacity()
{
return capacity;
}

/**
gets the distance traveled in miles
*/
public double getdistance()
{
return distance;
}
/**
gets the amount of gas that currently available in the tank in gallons
*/

public double getGasAvailable()
{
return gasAvailable;
}
/**
returns the amount of gas that can currently be added to the taknk in gallons
*/
public double getSpace()
{
emptySpace = capacity - gasAvailable;
return emptySpace;
}


}
/**
takes out gas from the gas tank
*/
/*
public boolean withdraw(double amount)
{

emptySpace = capacity - gasAvailable;

if (emptySpace <=0 )
return false;
else if(gallons > emptySpace ) {
gasAvailable =gasAvailable +emptySpace;
return true;
}
else{
gasAvailable= gasAvailable +gallons;
true;


}
}
}

/**
Transfers the specified gas from the strangersCar to MasoodsCar
*/
/*
public double Transfer(double amount);
{
double transfer Amount = gasTransferAmount;
strangersCar.withdraw(gasTransferAmount);
masoodsCar.deposit(gasTransferAmount);
}
*/






below is the tester that i have tried to do but know is completely incorrect


public class CarTester
{
public static void main(String[]args)
{
// this will test the Car object

Car gallons = new gallons(10);

gallons = 0;
if gallons (<= 10.0);
return
System.out.println("add more gas");
gallons = 10;
else if gallons >=(0.0);
return
System.out.println("Do not add more gas");
}

public static void main(String[]args);
{
miles = 0;
if (miles <= 10.0);
return
System.out.println("The car has travelled");
miles = 10;
else if (miles >= 0.0);
return
System.out.println("the car has not traveled at all");
}

public static void main(String[]args);
{
// int...

system.out.println();

}
}
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Please Use Code Tags, and also Ease Up.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Amaad Isam
Greenhorn

Joined: Oct 30, 2008
Posts: 3
Sorry about that. here is the code using the code tags.

the program i have written and know works:







below is the tester that i have tried to do but know is completely incorrect


Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi there,

Have you had a look at JUnit, you'll find it gives you a test framework as well as tips and tricks on how to write effective tests.

Good luck!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Desperately need help writing Tester
 
Similar Threads
Challange to write a program
Type not found in local declaration
Noob java assigment
Math question (very beginner)
Odometer