Untitled
unknown
plain_text
2 years ago
5.8 kB
17
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 LabMishMashSwitch{ /* 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 FORMATTING System.out.println("\n\n*** TASK Input Validation \n"); System.out.println("What is your GPA? "); double gpa = in.nextDouble(); //Write code that will print the value with 1 place after the decimal using printf String sGpa = String.format("%.1f",gpa); System.out.println(sGpa); //Write code that will display the value with 3 decimal places using printf System.out.println(String.format("%.3f",gpa)); // Run with various input to determine whether Java truncates or rounds int hours = 15; String name = "Spongebob"; String example =String.format("Name: %s Hours Enrolled %d %.3f", name, hours, gpa); //Use println to print the example string above. //this is what you could use in a toString to format numbers //use specifiers %s for strings, %d for ints and %f for floats // *************** TASK CHARACTER SWITCH System.out.println("========================================================="); System.out.println("| Choose Your Class |"); System.out.println("========================================================="); System.out.println("1. Barbarian: A fierce warrior of primitive background\n" + " who can enter a battle rage."); System.out.println("\n2. Bard: An inspiring magician whose power echoes\n" + " the music of creation."); System.out.println("\n3. Cleric: A priestly champion who wields divine\n" + " magic in service of a higher power."); System.out.println("\n4. Druid: A priest of the Old Faith, wielding the\n" + " powers of nature and adopting animal forms."); System.out.println("\n5. Fighter: A master of martial combat, skilled with\n" + " a variety of weapons and armor."); System.out.println("\n6. Ranger: A warrior who combats threats on the edges\n" + " of civilization."); System.out.println("\n7. Rogue: A scoundrel who uses stealth and trickery\n" + " to overcome obstacles and enemies."); System.out.println("\n8. Sorcerer: A spellcaster who draws on inherent magic\n" + " from a gift or bloodline."); System.out.println("\n9. Wizard: A scholarly magic-user capable of\n" + " manipulating the structures of reality.\n"); int classInput = in.nextInt(); String character = ""; switch(classInput){ case 1: case 5: character = "Strength"; break; case 2: case 8: character = "Charisma"; break; case 3: case 4: character = "Wisdom"; break; case 6: case 7: character = "Dexterity"; break; case 9: character = "Intelligence"; break; default: character = ""; } /* Remove the block comment above so that the print statements will instruct the user to select a character. Print the primary ability based on the choice USING AN IF STATEMENT Strength: Barbarians and Fighters Charisma: Bard and Sorcerers Wisdom: Clerics and Druids Dexterity: Rangers and Rogues Intelligence: Wizards */ System.out.println("\n\n*** TASK Game Character Switch \n"); // Print the primary ability based on the choice USING A SWITCH STATEMENT System.out.println(character); // TASK LEAVE //Use any decision statement you wish //Ask the user for level (1,2 or 3) and ask how many months worked (integer) // and you print hours leave per pay period based on table //1. Trainee // 0 - 12 get 4 hours // 12 - 24 get 6 hours // 25+ get 8 hours //2. Advanced // 0 - 24 get 8 hours // 25+ get 10 hours //3. Expert // 12 hours no matter how many months System.out.print("Enter level Trainee(1) Advanced(2) Expert(3): "); int level = in.nextInt(); System.out.print("Enter Months: "); int months = in.nextInt(); int hoursLeave = 0; switch(level){ case 1: if( months < 12){ hoursLeave = 4; }else if (months <24){ hoursLeave = 6; }else{ hoursLeave = 12; } break; case 2: if(months < 24){ hoursLeave = 8; }else{ hoursLeave = 10; } break; case 3: hoursLeave = 12; break; default: break; } System.out.println("You can get "+hoursLeave + " hours leave per pay period"); } } //end MishMash
Editor is loading...