* * Project04.java * A Java program that will play a simple game of Dragon Trainers. * Used to get familiar with Java language. * */ package osu.cse1223;
Make it run able
/*
* Project04.java
* A Java program that will play a simple game of Dragon Trainers.
* Used to get familiar with Java language.
*
*/
package osu.cse1223;
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++;
}
}
}
This study source was downloaded by 100000826278410 from CourseHero.com on 05-19-2021 07:35:51 GMT -05:00
https://www.coursehero.com/file/38318047/project-4java/
This study resource was
shared via CourseHero.comint 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!");
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images