Write a program that determines all the different ways for a player to score a certain number of points in a basketball game. Three pointers are worth 3 points (duh), field goals are worth 2 points, and foul shots are worth 1 point each. Be sure to print the total number of combinations at the end.
Run:
How many points were scored? 8
2 three pointer(s), 1 field goal(s), 0 foul shot(s)
2 three pointer(s), 0 field goal(s), 2 foul shot(s)
1 three pointer(s), 2 field goal(s), 1 foul shot(s)
1 three pointer(s), 1 field goal(s), 3 foul shot(s)
1 three pointer(s), 0 field goal(s), 5 foul shot(s)
0 three pointer(s), 4 field goal(s), 0 foul shot(s)
0 three pointer(s), 3 field goal(s), 2 foul shot(s)
0 three pointer(s), 2 field goal(s), 4 foul shot(s)
0 three pointer(s), 1 field goal(s), 6 foul shot(s)
0 three pointer(s), 0 field goal(s), 8 foul shot(s)
There are 10 different ways to score 8 points
What I have so far:
import java.util.Scanner;
public class MarchMadness
{
public static void main(String[] args)
{
Scanner kbReader = new Scanner(System.in);
System.out.println("How many points were scored?");
int points = kbReader.nextInt();
int ft = 1;
int fg = 2;
int tp = 3;
if (points % tp == 0)
{
System.out.println((points/tp) + " three pointers.");
}
}
}
I know how to make the program applicable to SPECIFIC situations, like 8 points, but I do not know how to make it accept any amount of points and get the correct output or print out the number of possible solutions. What should I do?