Question: I am creating class name RideRequest where I have given few test to check my code. I am able to pass almost all the test

I am creating class name RideRequest where I have given few test to check my code. I am able to pass almost all the test except few of them . Please help me figure out where i am doing wrong . these are instance variable of RideRequest class
private String customerName;
private String rideDetails;
private double ridePrice;
private boolean hasDiscount;
private static double taxrate;
private static double discount;
private static int toStringCounter =0;
I am having issue with last one toStringCounter where i need to increase its count with every jUnit test , there are total 5 jUnit test related to ToStringCounter where i need to print expected output . I am able to do all the calculations and had figured out what spacing need to be done to get expected output that aligns with JUnit test but with every test running my counter is not incerasing its value keep remains to one . Please help me figure what chnage do i need to make to get following output right -
this first test i got it rigth public void test_7_0(){
RideRequest request = new RideRequest(" Kate , Woodbine ,35.25, Y ");
RideRequest.setTaxrate(0.1); // Assuming 10% tax rate
RideRequest.setDiscount(0.2); // Assuming 20% discount rate
String expectedOutput ="1. Kate |Woodbine |38.78|31.02";
assertEquals("toString method failed", expectedOutput, request.toString());
but when second test run my counter does not increse and its value remains to 1. here is second test-public void test_7_1(){
RideRequest request = new RideRequest(" Susan ,Mississauga ,7.99, Y ");
RideRequest.setTaxrate(0.1); // Assuming 10% tax rate
RideRequest.setDiscount(0.2); // Assuming 20% discount rate
String expectedOutput ="2. Susan |Mississauga |8.79|7.03";
assertEquals("toString method failed", epublic void test_7_3(){
RideRequest request = new RideRequest(" Jack , North York ,9.99, N ");
RideRequest.setTaxrate(0.15); // Assuming 15% tax rate
RideRequest.setDiscount(0.25); // Assuming 25% discount rate
String expectedOutput ="4. Jack |North York |11.49|";
assertEquals("toString method failed", expectedOutput, request.toString());xpectedOutput, request.toString());
Providing other tests for more info public void test_7_3(){
RideRequest request = new RideRequest(" Jack , North York ,9.99, N ");
RideRequest.setTaxrate(0.15); // Assuming 15% tax rate
RideRequest.setDiscount(0.25); // Assuming 25% discount rate
String expectedOutput ="4. Jack |North York |11.49|";
assertEquals("toString method failed", expectedOutput, request.toString());
This is my code , i have created getter and increment method to increase its value but seems like its not working. Please provide code in toString method for conter to increse with every JUnit test public static void increment() i
tostringcounter++;
}
public static int getToStringCounter()(
return tostringCounter;
}
public String toString(){
RideRequest.increment();
double disAmount =0;
double Amount = Math.round(ridePrice*(1+ taxrate)*100.0)/100.0;
if (hasDiscount){
disAmount = Math.round(Amount*(1- discount)*100.0)/100.0;
}
String formattedOutput = String.format("%d.%-10s|%-24s |%.2f |%.2f", RideRequest.getToStringCounter(), customerName,rideDetails, Amount, disAmount);
return formattedOutput;
}
 I am creating class name RideRequest where I have given few

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!