Develop the game using the concepts of Cohesion, Coupling and RDD, i.e., respons
ID: 3551214 • Letter: D
Question
- Develop the game using the concepts of Cohesion, Coupling and RDD, i.e., responsibility-driven design.
- Note that each class should represent one logical entity
- Also note that each method should perform one logical task
- Aim for high cohesion and low coupling
- Atleast 3 classes.
Explanation / Answer
public class Player{ public boolean isHuman; public int score =0; private Scanner input; public Player(int human){ if(human > 0) isHuman=true; else isHuman=false; } public void play(){ if(isHuman) playHuman(); else playComp(); } public void playHuman(){ input =new Scanner(System.in); int current = 0; //int payment =0; int again =1; while (again==1){ System.out.println("Enter a 1 or 2 for your throw"); current = input.nextInt(); int value = (int) Math.random() * 3; score = (current + value); if(score % 2==0) System.out.println("You Win!"); else System.out.println("Sorry, you lose."); } } public void playComp(){ int current =0; int payment =0; int value = (int) Math.random() * 5; score = (current + value); } }public class Player{ public boolean isHuman; public int score =0; private Scanner input; public Player(int human){ if(human > 0) isHuman=true; else isHuman=false; } public void play(){ if(isHuman) playHuman(); else playComp(); } public void playHuman(){ input =new Scanner(System.in); int current = 0; //int payment =0; int again =1; while (again==1){ System.out.println("Enter a 1 or 2 for your throw"); current = input.nextInt(); int value = (int) Math.random() * 3; score = (current + value); if(score % 2==0) System.out.println("You Win!"); else System.out.println("Sorry, you lose."); } } public void playComp(){ int current =0; int payment =0; int value = (int) Math.random() * 5; score = (current + value); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.