code
unknown
java
3 years ago
5.3 kB
21
Indexable
// Race info taken from https://www.dndbeyond.com/compendium/rules/basic-rules/races
// Class info taken from https://www.dndbeyond.com/characters/classes
// Alignment info taken from https://www.dndbeyond.com/compendium/rules/basic-rules/personality-and-background#Alignment
import java.util.Scanner;
public class LabMishMashS23
{
/*
This is not one single program but rather snippets of code that might be
included in methods inside a class
Work your way progressively through the tasks as instructed in comments
Work on ONE task at a time.
*/
public static void main (String [] args)
{
Scanner in = new Scanner(System.in);
// *************** TASK MAGIC WORD
System.out.println("\n\n*** TASK Magic Word \n");
System.out.println("Enter the magic word ");
// String input = in.next();
String input = "A";
//Write code that will print BAZINGA! when the user types the word Please.
//Make sure you account for any variation of upper and lower case.
//When the user types anything other than Please, print NOPE!
if(input.toUpperCase().equals("PLEASE")){
System.out.println("BAZINGA!");
}else{
System.out.println("NOPE!");
}
// **************** TASK COPY CAT
//System.out.println("\n\n*** TASK Copy Cat \n");
System.out.println("How many copies are you making? ");
int copies = in.nextInt();
/*Write code that will calculate and print the cost of copies assuming that copies are
5 cents each for the first 100 copies
and 4 cents for any copies over 100
So for 50 copies the cost would be $2.50
and for 106 copies the cost would be $5.24 ($5 for the first 100 plus 0.04 * 6)
*/
int lessThanHund = copies;
int moreThanHund =0;
if(copies >100){
lessThanHund = 100;
moreThanHund = copies - 100;
}
double cost = lessThanHund*0.05 + moreThanHund * 0.04;
System.out.println(cost);
// ************** TASK Alter Ego
//Write code to print the alter ego based on the user's response or
//print "not a valid selection"
System.out.println("\nWhich alter ego do you want to know? \n");
System.out.println("\n 1. Iron Man");
System.out.println("\n 2. Wonder Woman");
System.out.println("\n 3. Hulk");
int choice = in.nextInt();
if(choice == 1){
System.out.println("Iron MAN has IRON");
}else if(choice == 2){
System.out.println("Wonder Woman is Wonderful");
}else{
System.out.println("Hulk never dies");
}
// ************** TASK Grade
System.out.println("\n\n*** TASK Letter Grade \n");
System.out.println("\n Enter a grade between 0 and 100 and I will tell you your letter grade. \n");
int grade = in.nextInt();
String letterGrade = "F";
if(grade >= 0){
if(grade <= 100){
if(grade >=90){
letterGrade = "A";
}else if(grade >=80){
letterGrade = "B";
}else if(grade >=70){
letterGrade = "C";
}else if (grade >=60){
letterGrade = "D";
}
}
}
System.out.println("Grade ==== " + letterGrade);
//add an input statement for the integer grade and then an if else chain to print the grade
//note: we haven't covered ANDs or OR's
//if you arrange your if-else chain appropriately, you don't need it
//**************** BEACON
//The beacon light on top of Boston's John Hancock building forecasts the weather:
// Steady blue, clear view.
// Flashing blue, clouds due.
// Steady red, rain ahead.
// Flashing red, snow instead.
System.out.println("\n\n*** TASK Beacon \n");
System.out.println("\n Enter 1 for blue or 2 for red");
int color = in.nextInt();
System.out.println("\n Enter 1 for steady or 2 for flashing");
int status = in.nextInt();
//Print the weather based on the user's input. Again we don't have relational operators like ANDs and ORs yet.
if(color==1){
System.out.print("Blue ");
}else if(color == 2){
System.out.print("RED ");
}
if(status == 1){
System.out.println("Steady");
}else if(status == 2){
System.out.println("Flashing");
}
// **************** TASK AURA
System.out.println("\n\n*** TASK Aura \n");
System.out.println("Enter a number between 0 and 9 and I will guess your aura ");
int number = in.nextInt();
String aura = "";
String possibleAura = "AmberAzureBerylCoralHazelIvoryLilacMochaOlivePeach";
// Write code that will set aura as a 5 letter substring of the string above with the starting
// position being 5 times the number the user just entered.
// For example if the user enters 3 the aura is Coral
// HINT: you are looking for a SUBSTRING
//THIS IS NOT AN IF STATEMENT PROBLEM
aura = possibleAura.substring(number*5, (number*5) + 5);
System.out.print("I am sensing your aura today is a lovely shade of "+ aura);
}
} //end MishMashEditor is loading...