I can't understand why the runtime appears to be completely ignoring the nested switch (act). I run the program and everything else runs fine but it's as if that part of the code isn't even there. It gets as far as the test code in the first switch (clr) case '3': but for some reason, no further.
Console follows the code.
// an easy to use program to hold snooker match scores and feed detailed statistics to the user import java.util.Scanner; public class SnookerStats{ // interface to take points for player if ball is potted--------------------------------------- interface Score{ // top level interface class for colour selection public abstract int take(int point); // abstract method } // interface to give points to other player if ball is fouled--------------------------------- interface Foul{ // interface for points for fouls public abstract int give(int point); } static class GreenClass implements Score, Foul{ public int take(int point){ // method to return point value for green ball potted int r = point + 3; return r; } public int give(int point){ int r = 4; return r; } } public static void main(String args[]){ Scanner sc = new Scanner(System.in); int temp, brk=0; // temp holds number of frames, brk holds current break tally int [][] blsprfrm; // 2D array for each ball per frame int wht, ylw, grn, brw, blu, pnk, blk; // argument to count number of balls potted int scwht, scylw, scgrn, scbrw, scblu, scpnk, scblk; // if potted, collects score, if fouled, collects points for other player boolean active1 = false, active2 = true; // active break yes or no char clr, act; // option variables to hold colour and action upon colour Score green = new GreenClass(); // request number of frames from user System.out.println("Number of frames to play: "); temp = sc.nextInt(); // multidemensional array _ balls potted per frame blsprfrm = new int [temp][7]; // temp collects number of frames from user, 7 is number of ball types on table System.out.println("Number of frames to play: " + blsprfrm.length); System.out.println("Number of ball types on table: " + blsprfrm[0].length); // ask which ball player is striking System.out.println("Select colour:\n1 : White\n2 : Yellow\n3 : Green\n4 : Brown\n5 : Blue\n6 : Pink\n7 : Black "); clr = sc.next().charAt(0); // player pot or safety System.out.println("Select from the following options:\nP : Pot\nM : Miss\nS : Safety\nF : Foul"); act = sc.next().charAt(0); System.out.println("Colour selected: "+ clr); System.out.println("Action selected: "+ act); switch (clr){ case '3': System.out.println("Green ball selected."); switch (act){ case 'P': brk = green.take(brk); System.out.println("Points for green ball: "+ brk); break; } break; } } }
Number of frames to play: 3 Number of frames to play: 3 Number of ball types on table: 7 Select colour: 1 : White 2 : Yellow 3 : Green 4 : Brown 5 : Blue 6 : Pink 7 : Black 3 Select from the following options: P : Pot M : Miss S : Safety F : Foul p Colour selected: 3 Action selected: p Green ball selected.
--- Update ---
Rookie error.
I know switch cases are case sensetive but I mistakingly thought that I had tested that.
It was a higher capital P in the case condition.