MAke this code runnable with output
import java.util.Scanner;
public class Project04 {
public static void main(String[] args) {
Scanner keyboard=new Scanner(System.in);
int win = 0,lose=0, tie=0;
while (win<2) {
System.out.print("Please select one of your dragons
[Fire/Plant/Water]: ");
String player=keyboard.nextLine();
System.out.println("You chose: " + player + " dragon");
int x=(int) Math.floor(Math.random()*3+1);
String fire1="Fire",fire2="FIRE",fire3="fire",fire4="F",fire5="f";
String
plant1="Plant",plant2="PLANT",plant3="plant",plant4="P",plant5="p";
String
water1="Water",water2="WATER",water3="water",water4="W",water5="w";
if (x==1) {
String CPU="Fire";
System.out.println("I chose: " + CPU + " dragon");
if (player.equalsIgnoreCase(fire1)||
player.equalsIgnoreCase(fire2)||player.equalsIgnoreCase(fire3)||
player.equalsIgnoreCase(fire4)||player.equalsIgnoreCase(fire5)) {
System.out.println("A Tie!");
tie++;
}
else if(player.equalsIgnoreCase(plant1)||
player.equalsIgnoreCase(plant2)||player.equalsIgnoreCase(plant3)||
player.equalsIgnoreCase(plant4)||player.equalsIgnoreCase(plant5)) {
System.out.println("Fire defeats " + player + " - you
lose!");
lose++;
}
else if (player.equalsIgnoreCase(water1)||
player.equalsIgnoreCase(water2)||player.equalsIgnoreCase(water3)||
player.equalsIgnoreCase(water4)||player.equalsIgnoreCase(water5)) {
System.out.println(player + " defeats fire - you win!");
win++;
}
else if(player !=fire1||player!=fire2||player!=fire3||player=fire4||player!=fire5||player!=plant1||player!=plant2||player!=plant3||player!=plant4||player!=plant5||player!=water1||player!=water2||player!=water3||player!=water4||player!=water5) {
System.out.println("You lose by default!");
lose++;
}
}
if (x==2) {
String CPU="Plant";
System.out.println("I chose: " + CPU + " dragon");
if (player.equalsIgnoreCase(fire1)||
player.equalsIgnoreCase(fire2)||player.equalsIgnoreCase(fire3)||
player.equalsIgnoreCase(fire4)||player.equalsIgnoreCase(fire5)) {
System.out.println(player + " defeats plant - you
win!");
win++;
}
else if (player.equalsIgnoreCase(plant1)||
player.equalsIgnoreCase(plant2)||player.equalsIgnoreCase(plant3)||
player.equalsIgnoreCase(plant4)||player.equalsIgnoreCase(plant5)) {
System.out.println("A tie!");
tie++;
}
else if (player.equalsIgnoreCase(water1)||
player.equalsIgnoreCase(water2)||player.equalsIgnoreCase(water3)||
player.equalsIgnoreCase(water4)||player.equalsIgnoreCase(water5)) {
System.out.println("Plant defeats " + player + " - you
lose!");
lose++;
}
else if(player !=fire1||player!=fire2||player!=fire3||player!
=fire4||player!=fire5||player!=plant1||player!=plant2||player!=plant3||player!
=plant4||player!=plant5||player!=water1||player!=water2||player!=water3||player!
=water4||player!=water5) {
System.out.println("You lose by default!");
lose++;
}
}
if (x==3) {
String CPU="Water";
System.out.println("I chose: " + CPU + " dragon");
if (player.equalsIgnoreCase(fire1)||
player.equalsIgnoreCase(fire2)||player.equalsIgnoreCase(fire3)||
player.equalsIgnoreCase(fire4)||player.equalsIgnoreCase(fire5)) {
System.out.println("Water defeats " + player + " - you
lose!");
lose++;
}
else if (player.equalsIgnoreCase(plant1)||
player.equalsIgnoreCase(plant2)||player.equalsIgnoreCase(plant3)||
player.equalsIgnoreCase(plant4)||player.equalsIgnoreCase(plant5)) {
System.out.println(player + " defeats water - you
win!");
win++;
}
else if (player.equalsIgnoreCase(water1)||
player.equalsIgnoreCase(water2)||player.equalsIgnoreCase(water3)||
player.equalsIgnoreCase(water4)||player.equalsIgnoreCase(water5)) {
System.out.println("A tie!");
tie++;
}
else if(player !=fire1||player!=fire2||player!=fire3||player!
=fire4||player!=fire5||player!=plant1||player!=plant2||player!=plant3||player!
=plant4||player!=plant5||player!=water1||player!=water2||player!=water3||player!
=water4||player!=water5) {
System.out.println("You lose by default!");
lose++;
}
}
}
int y=win+lose+tie;
System.out.println("Out of " + y + " matches you won " + win + ", I
won " + lose + ", and we tied " + tie + ".");
System.out.println("Congratulations - you win the tournament!");
}
}
93
Step by stepSolved in 2 steps with 1 images
- complete the missing code. public class Exercise09_04Extra { public static void main(String[] args) { SimpleTime time = new SimpleTime(); time.hour = 2; time.minute = 3; time.second = 4; System.out.println("Hour: " + time.hour + " Minute: " + time.minute + " Second: " + time.second); } } class SimpleTime { // Complete the code to declare the data fields hour, // minute, and second of the int type }arrow_forwardpublic class Course{String name;String dept;int number;public Course (String n, String d, int n){name = n;dept = d;number = n;}public String toString(){return "Course " + name + " in " + dept + " #: " + number;}public static void main (String [] args){Scanner in = new Scanner(System.in);add 10 lines using the scanner and saving them as strings The input for each line will be entered a String, a space, another String, and an int. Parse the input string into those three items and make an instance of Course. Add the new Course instance to a generic ArrayList of Course. print out each Course in the ArrayList.arrow_forwardpublic static char start(char key) {Scanner console = new Scanner(System.in);String prompt = "Enter 'q' to quit. Any other key to continue...";double height;double weight;System.out.println("Enter something before you start : >>>>");while (key != 'q'){height = getHeight(console);weight = getWeight(console);displaySummary(height, weight);//prompt to quitSystem.out.println();System.out.print(prompt);key = console.next().charAt(0);}return key;} How can I test this one in the J-unit test?? Is it testable?arrow_forward
- Q: What's a better way to write this? (C#) public string SomeMethod(string OriginalZip) { string zip = "Zip Not Available"; zip = GetZip(zip, OriginalZip); return zip; } private static string GetZip(string zip, string OriginalZip) { int zipLength = (OriginalZip.HasValue) ? OriginalZip.Value.ToString().Length: 0; int NumOf Leading Zeroes = (zipLength > O && zipLength < 5) ? 5 - zipLength: 0; if (OriginalZip.HasValue) { i++) } zip = OriginalZip.Value.ToString(); for (int i = 0; i < NumOf Leading Zeroes; { } zip = "0" + zip; } return zip;arrow_forwardpublic class Animal { public static int population; private int age; } public Animal (int age) { this.age = age; population++; } + msg); public void say (String msg) { System.out.print("Saying: " System.out.print(" for "); System.out.print(getHuman Years()); System.out.println(" years."); } public int getHuman Years() { return age; } public class Mammal extends Animal { private String species; public Mammal(String species, int age) { super (age); this. species species; } } } = public int getHuman Years() { if (species.equals("dog")) 1 else return super.getHumanYears() * 7; return super.getHumanYears(); €arrow_forwardimport java.util.Scanner;public class MP2{public static void main (String[] args){//initialization and declarationScanner input = new Scanner (System.in);String message;int Option1;int Option2;int Quantity;int TotalBill;int Cash;int Change;final int SPECIALS = 1;final int BREAKFAST = 2;final int LUNCH = 3;final int SANDWICHES = 4;final int DRINKS = 5;final int DESSERTS = 6;//For the Special, Breakfast, Lunch Optionsfinal int Meals1 = 11;final int Meals2 = 12;final int Meals3 = 13;final int Meals4 = 14;//First menu and First OptionSystem.out.println("\t Welcome to My Kitchen ");System.out.println("\t\t SPECIALS");System.out.println("\t\t [2] BREAKFAST MEALS");System.out.println("\t\t [3] LUNCH MEALS");System.out.println("\t\t [4] SANDWICHES");System.out.println("\t\t [5] DRINKS");System.out.println("\t\t [6] DESSERTS");System.out.println("\t\t [0] EXIT");System.out.print("Choose an option ");Option1 = input.nextInt();//first switch case statementsswitch(Option1){case (SPECIALS):message…arrow_forward
- Java Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A, B, C, D, E" is correct. Each question has one correct answer. Thank you. Part 1 - Given the following code, the output is __. class Sample{ public static void main (String[] args){ try{ System.out.println(5/0);}catch(ArithmeticException e){ System.out.print("Divide by zero????");}finally{ System.out.println("5/0"); } }} A. Divide by zero????B. 5/0C. Divide by zero????5/0D. 5/0Divide by zero????E. "5/0" Part 2 - Given the following code, the output is __. try{ Integer number = new Integer("1"); System.out.println("An Integer instance.");}catch (Exception e){ System.out.println("An Exception.");} A. An Integer instance.B. An Exception.C. 1D. Error: ExceptionE. None of the optionsarrow_forwardusing System; class HelloWorld { static void Main() { int rows=21; int columns=76; for(int i=0;i<rows;i++) //for loop for printing the pattern for 21 rows { for(int j=1;j<=columns;j++) //for loop for printing the pattern in 76 columns { if((i+j)%7!=1 ) //if the addition of i and j does not give remainder of 1 when divided by 7 then Console.Write("-"); //print dash - on console else //otherwise peint a space on console Console.Write(" "); } Console.WriteLine(); //print a newline for printing on new row... } } }arrow_forwardpublic static class Lab2{public static void Main(){int idNum;double payRate, hours, grossPay;string firstName, lastName;// prompt the user to enter employee's first nameConsole.Write("Enter employee's first name => ");firstName = Console.ReadLine();// prompt the user to enter employee's last nameConsole.Write("Enter employee's last name => ");lastName = Console.ReadLine()// prompt the user to enter a six digit employee numberConsole.Write("Enter a six digit employee's ID => ");idNum = Convert.ToInt32(Console.ReadLine());// prompt the user to enter the number of hours employeeworkedConsole.Write("Enter the number of hours employee worked =>");// prompt the user to enter the employee's hourly pay rateconsole.Write("Enter employee's hourly pay rate: ");payRate = Convert.ToDouble(Console.ReadLine());// calculate gross paygrossPay = hours * payRate;// output resultsConsole.WriteLine("Employee {0} {1}, (ID: {2}) earned {3}",firstName, lastName, idNum,…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY