The goal: You will design a system to include the following modules. In this ass
ID: 3565047 • Letter: T
Question
The goal: You will design a system to include the following modules. In this assignment, you need to use method call among different classes. Pattern printout Random letter guessing Basic math operations For each module, you can use a separate class (Pattern Print, Letter Guess, Math Operator), meaning that you have three source files (.java files). Finally, you have a combination class (running class or running starting point of the project) to integrate all three modules together. Pattern Print Class: within the first module: pattern printout, you need to implement three class methods: print out a triangle, print out a diamond, and print out a "V". Those methods can be either static or non-static. For each method, you will get some parameters from outside users (e.g. the height of the triangle and the diamonds, etc.). Letter Guess Class: for the second module, you generate a random integer inclusively between 65 (Unicode value for the letter 'A') and 97 (Unicode value for the letter 'a'), and then convert the integer into a character using explicit conversion (This will result in a uppercase letter from A to Z). After that, you use loop and if-else statements to finish this guess module. It must have the following functionalities. Allow the user to keep guessing until the user gets finally succeeded in guessing. Your methods should be user-friendly. For example, if the guess is not correct, you should output a hint message to let the user know it.Explanation / Answer
For first part
public void trianglePrint(int h) {
for(int i=1;i<=h;i++) {
for(int j=0;j<h-i;j++) {
System.out.print(" ");
}
for(int j=1;j<2*i;j++) {
System.out.print("*");
}
System.out.print(" ");
}
}
public void diamondPrint(int h) {
trianglePrint(h/2+1);
for(int i=1;i<=h/2;i++) {
for(int j=1;j<=i;j++) {
System.out.print(" ");
}
for(int j=1;j<=h-2*i;j++) {
System.out.print("*");
}
System.out.print(" ");
}
}
public void vprint(int h) {
int l = 2*h-1;
for(int i=1;i<=h;i++) {
for(int j=1;j<2*i;j++) {
System.out.print("*");
}
for(int j=1;j<=2*l-4*i+2;j++) {
System.out.print(" ");
}
for(int j=1;j<2*i;j++) {
System.out.print("*");
}
System.out.print(" ");
}
}
For second Part
public class LetterGuess {
public void playGame() {
Scanner s = new Scanner(System.in);
Random r = new Random();
int random = r.nextInt(27);
random+=65;
String input;
do {
input = s.next();
if(input.charAt(0)==(char)random) {
System.out.println("You Guessed it correctly");
}
else {
System.out.println("Sorry your guess is incorrect");
}
} while(input.charAt(0)!=(char)random);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.