lab06 baseballstats use switch statement

This commit is contained in:
SowinskiBraeden committed 2025-02-18 11:35:03 -08:00
1 parent 83e5d02f4f
commit ba260607a0
1 file changed
+26 -4
+26 -4
View File
@@ -45,10 +45,32 @@ public class BaseballStats {
int walks = 0; int walks = 0;
while (lineScan.hasNext()) { while (lineScan.hasNext()) {
String current = lineScan.next(); String current = lineScan.next();
hits += current.equals("h") ? 1 : 0;
outs += current.equals("o") ? 1 : 0;
sacs += current.equals("s") ? 1 : 0; switch (current) {
walks += current.equals("w") ? 1 : 0; case "h":
hits += 1;
break;
case "o":
outs += 1;
break;
case "s":
sacs += 1;
break;
default:
walks += 1;
break;
}
/*
* Lab instructors want you to use switch
* statements as seen above
*
* hits += current.equals("h") ? 1 : 0;
* outs += current.equals("o") ? 1 : 0;
* sacs += current.equals("s") ? 1 : 0;
* walks += current.equals("w") ? 1 : 0;
*/
} }
System.out.print(hits + " hits, " System.out.print(hits + " hits, "