Nathan Compliments Extra Notebook
Compliments extra notebook
import java.util.Scanner;
class Compliments {
// Function that uses if, else if, and else to decide which compliment to print out.
public void nice(int choice){
if(choice == 1){
System.out.println("You're pretty!");
}
else if(choice == 2){
System.out.println("You're strong!");
}
else if(choice == 3){
System.out.println("You're cool!");
}
else if(choice == 4){
System.out.println("You're smart!");
}
else{
System.out.println("You did not choose an option for a random compliment!");
}
}
// Function that is converted to switch, case, and other to decide which insult to print out.
public void mean(int choice){
switch(choice){
case 1:
System.out.println("You're ugly!");
break;
case 2:
System.out.println("You're weak!");
break;
case 3:
System.out.println("You're lame!");
break;
case 4:
System.out.println("You're dumb!");
break;
case 5:
System.out.println("くコ:彡");
break;
default:
System.out.println("You did not choose an option for a random insult!");
}
}
}
// Objects created for Compliments class and Scanner for user input
Compliments comp = new Compliments();
Scanner scan = new Scanner(System.in);
// Prompts user to choose whether or not they want a compliment or insult and changes it into a boolean
System.out.println("Input 1 for a compliment and anything else for an insult: ");
int compOrInsult = Integer.parseInt(scan.nextLine());
boolean decision;
// compliment
if(compOrInsult == 1){
decision = true;
}
// insult
else{
decision = false;
}
// code block to prompt user to choose a random compliment
if(decision){
System.out.println("Input 1-4 for a random compliment: ");
int rand = Integer.parseInt(scan.nextLine());
System.out.println("This was printed using if-elseif-else: ");
comp.nice(rand);
}
// code block to prompt user to choose a random insult
else if(!decision){
System.out.println("Input 1-4 for a random compliment: ");
int rand = Integer.parseInt(scan.nextLine());
System.out.println("This was printed using switch-case-otherwise: ");
comp.mean(rand);
}