Plan, code and compile a BowlingLane class that will model a 5 Pin Bowling Lane. The bowling lane will have 5 pins which can be either upright or knocked down. Use 5 boolean variables to represent the pins. Next, create a client program that will:
public class BowlingLane {
boolean one;
boolean two;
boolean three;
boolean four;
boolean five;
public BowlingLane(boolean one, boolean two, boolean three, boolean four, boolean five) {
this.one = one;
this.two = two;
this.three = three;
this.four = four;
this.five = five;
}
}
import java.util.Scanner;
public class Main {
public static void classify(BowlingLane bowlingLane) {
if (!bowlingLane.one && !bowlingLane.two && !bowlingLane.three && !bowlingLane.four && !bowlingLane.five) {
System.out.println("X - Strike");
} else if (!bowlingLane.two && !bowlingLane.three && !bowlingLane.four) {
System.out.println("A - Aces.");
} else if ((!bowlingLane.two && !bowlingLane.three) || (!bowlingLane.three && !bowlingLane.four)) {
System.out.println("HS - Headsplit.");
}
int points = (!bowlingLane.one ? 2 : 0) + (!bowlingLane.two ? 3 : 0) + (!bowlingLane.three ? 5 : 0)
+ (!bowlingLane.four ? 3 : 0) + (!bowlingLane.five ? 2 : 0);
System.out.println("Points: " + points);
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter states of five bowling pins(1-Up | 2-Down):");
BowlingLane bowlingLane = new BowlingLane(in.next().equals("1"), in.next().equals("1"), in.next().equals("1"),
in.next().equals("1"), in.next().equals("1"));
System.out.println((bowlingLane.one ? "!" : ".") + (bowlingLane.two ? "!" : ".") + (bowlingLane.three ? "!" : ".") +
(bowlingLane.four ? "!" : ".") + (bowlingLane.five ? "!" : "."));
classify(bowlingLane);
}
}
Comments
Leave a comment