Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Write in Java a code give out what is on the image.

Essentially write in the main function so that it prints what is in the image.

Im stuck at that part it would be much appreciated if you could help.

package javaapplication31;

import java.util.Random;
import java.util.Scanner;
/**
*
* @author
*/
public class JavaApplication31 {
String name;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int totalScore = 300;
int itrcount =12;
int reward;
char direction;
int x = 0;
int y = 0;
System.out.println(reward());
System.out.println(inputDirection());
}


public static void displayInfo(int x, int y, int itrCount, int totalScore){
x = 0;
y = 0;
itrCount = 0;
totalScore =300;
System.out.println("");
}
public static boolean doesExceed (int x,int y, char direction){
return (y > 4 && Character.toLowerCase(direction) == 'u' || x < 0 && Character.toLowerCase(direction) == '1'||
y < 0 && Character.toLowerCase(direction) == 'd' || x > 4 && Character.toLowerCase(direction) == 'r');
}
public static int reward(){
Random rand = new Random ();
int dice = rand.nextInt(6)+1;

switch (dice){
case 1:
System.out.println("Dice: 1, reward: -100");
return -100;
case 2:
System.out.println("Dice: 2, reward: -200");
return -200;
case 3:
System.out.println("Dice: 3, reward: -300");
return -300;
case 4:
System.out.println("Dice: 4, reward: 300");
return 300;
case 5:
System.out.println("Dice: 5, reward: 400");
return 400;
default:
System.out.println("Dice: 6, reward: 600");
return 600;
}
}
public static int punishOrMercy(char direction, int reward){
if (reward < 0 && direction == 'u'){
Random rand = new Random();
int coin = rand.nextInt(3);
if (coin ==0)
System.out.println("Coin: tail | Mercy, the negative reward is removed. ");
else
System.out.println("Coin: head | No mercy, the negative reward is applied");
}
return reward;
}
public static String toTitleCase(String str){
char d = str.charAt(0);
String str1 = str.substring(1, str.indexOf (' ') +2);
String str2 = str.substring(str.indexOf(' '), str.indexOf(' ') +2);
char d1 = str2.charAt(1);
String str3 = str.substring(str.indexOf(' ') +2, str.length());
String str4 = Character.toTitleCase(d1) + str3.toLowerCase();
return str4;
}
public static void evaluation(int totalScore){
Scanner console = new Scanner(System.in);
System.out.println("Please enter your name (only two words) ");
String name = console.nextLine();
if (totalScore>2000)
System.out.println("Victory! " + toTitleCase(name) + ",your score is " +totalScore);
else
System.out.println("Mission failed! " + toTitleCase(name) + ", your score is " +totalScore);
}
public static char inputDirection(){
Scanner console = new Scanner(System.in);
char directionLetter = ' ';
boolean isValid;
do{
System.out.println("Please input a valid direction ");
directionLetter = console.next().toLowerCase().charAt(0);
isValid = (directionLetter == 'u' || directionLetter == 'd' || directionLetter == 'l' ||
directionLetter == 'r');
} while (!isValid);
return directionLetter;
}

public static boolean isGameOver(int x, int y, int totalScore, int itrCount){
if (itrCount > 20 || totalScore < 1000 || totalScore > 1000 || x ==4 && y ==4 || x==0 && y==0){
evaluation(totalScore);
return false;
}
else return false;
}
}

[画像:For point (X=0, Y=0) at iteration: 0 the total score is: 300 Please input a valid direction: u Dice: 2, reward: -200 Coin: tail | Mercy, the negative reward is removed. For point (X=0, Y=1) at iteration: 1 the total score is: 290 Please input a valid direction: r Dice: 3, rew ard: -300 For point (X=1, Y=1) at iteration: 2 the total score is: 240 Please input a valid direction: u Dice: 5, reward: 400 For point (X=1, Y=2) at iteration: 3 the total score is: 630 Please input a valid direction: r Dice: 4, reward: 300 For point (X=2, Y=2) at iteration: 4 the total score is: 880 Please input a valid direction: u Dice: 2, reward: -200 Coin: head | No mercy, the negative revawed is applied. For point (X-2, Y=3) at iteration: 5 the total score is: 670 Please input a valid direction: r Dice: 6, reward: 600 For point (X=3, Y=3) at iteration: 6 the total score is: 1220 Please input a valid direction: u Dice: 2, rew ar d: -200 Coin: tail | Mercy, the negative reward is removed. For point (X=3, Y=4) at iteration: 7 the total score is: 1210 Please input a valid direction: u Exceed boundary, -2000 damage applied Dice: 2, reward: -200 Coin: head | No mercy, the negative rewawed is applied. For point (X=3, Y=4) at iteration: 8 the total score is: -1000 Please input a valid direction: r Dice: 6, reward: 600 Please enter your name (only two words): jon snow Mission failed! Jon Snow, your score is -450 ]
expand button
Transcribed Image Text:For point (X=0, Y=0) at iteration: 0 the total score is: 300 Please input a valid direction: u Dice: 2, reward: -200 Coin: tail | Mercy, the negative reward is removed. For point (X=0, Y=1) at iteration: 1 the total score is: 290 Please input a valid direction: r Dice: 3, rew ard: -300 For point (X=1, Y=1) at iteration: 2 the total score is: 240 Please input a valid direction: u Dice: 5, reward: 400 For point (X=1, Y=2) at iteration: 3 the total score is: 630 Please input a valid direction: r Dice: 4, reward: 300 For point (X=2, Y=2) at iteration: 4 the total score is: 880 Please input a valid direction: u Dice: 2, reward: -200 Coin: head | No mercy, the negative revawed is applied. For point (X-2, Y=3) at iteration: 5 the total score is: 670 Please input a valid direction: r Dice: 6, reward: 600 For point (X=3, Y=3) at iteration: 6 the total score is: 1220 Please input a valid direction: u Dice: 2, rew ar d: -200 Coin: tail | Mercy, the negative reward is removed. For point (X=3, Y=4) at iteration: 7 the total score is: 1210 Please input a valid direction: u Exceed boundary, -2000 damage applied Dice: 2, reward: -200 Coin: head | No mercy, the negative rewawed is applied. For point (X=3, Y=4) at iteration: 8 the total score is: -1000 Please input a valid direction: r Dice: 6, reward: 600 Please enter your name (only two words): jon snow Mission failed! Jon Snow, your score is -450
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education