I’ve been working on a program that is supposed to output the winning status of a racing cart. I thought I had everything set up correctly, and followed my instructor’s outline in class last week. However, in doing so I cannot get the output to print. My thought is that I may be stuck in a loop, but I don’t really know how to get out of it. I’ve been working on it for four hours now, and have searched for answers low and high to no avail. I get no errors when compiling, so I’m not sure what the issue could be.
import java.util.*;
import java.math.*;
public class Assignment2{
public static void main(String args[]){
}
int r, cart, value;
public void race(){ //generates random number to assign value to cart
Random ran = new Random();
int r = ran.nextInt(0) + 6;
value = r;
}
public int getValue(){ //assigns value to carts
return value;
}
public void display(){ //sys.out to print results
race();
if (value == 5){
System.out.println("______");
System.out.println("|____| Winning Status = 5");
System.out.println(" o o");
}
else if(value == 4){
System.out.println("______");
System.out.println("|____| Winning Status = 4");
System.out.println(" o o");
}
else if(value == 3){
System.out.println("______");
System.out.println("|____| Winning Status = 3");
System.out.println(" o o");
}
else if(value == 2){
System.out.println("______");
System.out.println("|____| Winning Status = 2");
System.out.println(" o o");
}
else if(value == 1){
System.out.println("______");
System.out.println("|____| Winning Status = 1");
System.out.println(" o o YOU'RE FIRST! CONGRATS!");
}
}
}
There is nothing in your
main()method, so nothing is actually executed. Perhaps you mean:As your code exists now, you should do away with
r(it is unused) and change the following: