Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program: 1: Create a program that generates a random integer between 0 and 99 (i

ID: 3883613 • Letter: P

Question

Program: 1: Create a program that generates a random integer between 0 and 99 (inclusive). If the integer is divisible by 5, print "Wake." If the integer is divisible by 7, print "Tech." If the integer is divisible by both 5 and 7, print "WakeTech." Otherwise, print the number.

Program 2:

Did You Ever Have To Make Up Your Mind?

Write a program using Scanner to help you decide what to do this weekend.

Decision Trees
Imagine you only ever do three things at the weekend: go shopping, watch a movie, or just stay in. What you do depends on three things: the weather (good or bad); how much money you have (rich or poor) and whether your parents are visiting. You say to your yourself: if my parents are visiting, we'll go to the cinema. If they're not visiting and the weather's good and I'm rich, then I'll go shopping. If they're not visiting, and the weather's good and I'm poor, then I will go to the cinema. If they're not visiting and the weather is bad and I'm rich, I'll go to the cinema. If they're not visiting and the weather is bad and I'm poor, I'll stay in.

Create a program asking whether the parents are visiting, whether the weather is good, and whether you are rich or poor. Your program should print "go to the cinema" "go shopping" or "stay in" as appropriate.

Hint: There are two possibilities for the "Parents visiting?" question, two for the "is weather good?" question, and two for the "are you rich?" question. That gives eight possible cases:

The problem can be solved by testing a lot fewer cases than 8, but if you get confused, the full 8 case solution might provide a way to understand all of the possibilities.

Truth Table for Did You Ever Have to Make Up Your Mind? Are parents visiting? Is the weather good? Are you rich? What you do y y y y y n y n y y n n n y y n y n n n y n n n

Explanation / Answer

program 1:

import java.util.Random;

public class RandomNum {

public static void main(String[] args) {

// create a new Java Random object

Random random = new Random();

int num = random.nextInt(100);

if (num % 5 == 0 && num % 7 == 0) {

System.out.println("WakeTech.");

} else if (num % 5 == 0) {

System.out.println("Wake.");

} else if (num % 7 == 0) {

System.out.println("Tech.");

}

else{

System.out.println(num);

}

}

}

Program 2:

import java.util.Scanner;

public class MakeUrMind {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.println("Are parents visiting?(y/n)");

String parentsVisting = scanner.nextLine();

System.out.println("Is the weather good?(y/n)");

String weatherCondition = scanner.nextLine();

System.out.println("Are you rich?(y/n)");

String rich = scanner.nextLine();

if (null != parentsVisting && null != weatherCondition && null != rich) {

if (parentsVisting.equalsIgnoreCase("y")) {

System.out.println("go to the cinema");

} else if (parentsVisting.equalsIgnoreCase("n")) {

if (weatherCondition.equalsIgnoreCase("y")) {

if (rich.equalsIgnoreCase("n")) {

System.out.println("go to the cinema");

} else if (rich.equalsIgnoreCase("y")) {

System.out.println("go shopping");

}

} else if (weatherCondition.equalsIgnoreCase("n")) {

if (rich.equalsIgnoreCase("n")) {

System.out.println("stay in");

} else if (rich.equalsIgnoreCase("y")) {

System.out.println("go to the cinema");

}

}

}

}

}

}