* * Project04.java * A Java program that will play a simple game of Dragon Trainers. * Used to get familiar with Java language. * */ package osu.cse1223;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

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!");
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY