Related questions
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;
}
}
Step by stepSolved in 3 steps
- 1 import java.util.Scanner; 3 public class TriangleArea { INM&567 000 2 4 8 9 10 11 12 13 14 15 4567890 16 17 18 19 20 21 } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); } Current file: TriangleArea.java = Triangle triangle1 new Triangle(); Triangle triangle2 = new Triangle(); // TODO: Read and set base and height for triangle1 (use setBase() and setHeight()) // TODO: Read and set base and height for triangle2 (use setBase() and setHeight()) System.out.println("Triangle with smaller area:"); // TODO: Determine smaller triangle (use getArea()) // and output smaller triangle's info (use printInfo())arrow_forwardJAVA CODE: check outputarrow_forwardWrite code that prints: countNum ... 21 Print a newline after each number. Ex: If the input is: 3 the output is: 3 2 1 1 import java.util.Scanner; 3 public class ForLoops { UAWN HOUх и блашин 2 ST 4 5 6 7 8 9 10 11 12 13 14 15 } public static void main (String [] args) { int countNum; int i; Scanner input = new Scanner(System.in); input.nextInt(); countNum = for * Your code goes here *) { System.out.println(i); } }arrow_forward
- Implement the Board class. Make sure to read through those comments so that you know what is required. import java.util.Arrays; import java.util.Random; public class Board { // You don't have to use these constants, but they do make your code easier to read public static final byte UR = 0; public static final byte R = 1; public static final byte DR = 2; public static final byte DL = 3; public static final byte L = 4; public static final byte UL = 5; // You need a random number generator in order to make random moves. Use rand below private static final Random rand = new Random(); private byte[][] board; /** * Construct a puzzle board by beginning with a solved board and then * making a number of random moves. Note that making random moves * could result in the board being solved. * * @param moves the number of moves to make when generating the board. */ public Board(int moves) { // TODO } /** * Construct a puzzle board using a 2D array of bytes to indicate the contents *...arrow_forwardPlease help and thank you in advance. The language is Java. I have to write a program that takes and validates a date but it won't output the full date. Here is my current code: import java.util.Scanner; public class P1 { publicstaticvoidmain(String[]args) { // project 1 // date input // date output // Create a Scanner object to read from the keyboard. Scannerkeyboard=newScanner(System.in); // Identifier declarations charmonth; intday; intyear; booleanisLeapyear; StringmonthName; intmaxDay; // Asks user to input date System.out.println("Please enter month: "); month=(char)keyboard.nextInt(); System.out.println("Please enter day: "); day=keyboard.nextInt(); System.out.println("Please enter year: "); year=keyboard.nextInt(); // Formating months switch(month){ case1: monthName="January"; break; case2: monthName="February"; break; case3: monthName="March"; break; case4: monthName="April"; break; case5: monthName="May"; break; case6: monthName="June"; break; case7:...arrow_forwardImplement a date picker in javafx having following properties1) only numerical value can be typed in it2) / ( forward slash) appears in it when form prompt and user can write date in it3)only 8 digits can be typed in itarrow_forward
- in javaarrow_forwardIn Java fix this problem so that it can run. The flawed pieces are highlighted -Also, use char instead of ch -Make sure it will run in java language via intellij public class Image {int numberOfPhotos; // photos on rolldouble fStop; // light let it 1.4,2.0,2.8 ... 16.0int iso; // sensativity to light 100,200, 600int filterNumber; // 1-6String subjectMatter;String color; // black and white or colorString location;boolean isblurry;public String looksBlurry(boolean key){if ( key == true){return "Photo is Blurry";}else{return "Photo is Clear";}}public void printPhotoDetails (String s1){Scanner br= new Scanner(System.in);String subjectMatter=s1;System.out.println("Data of Nature photos:");System.out.println("Enter number of photos:");numberOfPhotos= br.nextInt();int i=1;while(true){System.out.println("Enter Filter number of photos"+i+":");filterNumber= br.nextInt();System.out.println("Enter colour of photo"+i+ ":");String color= br.next();System.out.println("Enter focal length of...arrow_forwardimport java.util.Scanner; public class LabProgram { public static Roster getInput(){ /* Reads course title, creates a roster object with the input title. Note that */ /* the course title might have spaces as in "COP 3804" (i.e. use nextLine) */ /* reads input student information one by one, creates a student object */ /* with each input student and adds the student object to the roster object */ /* the input is formatted as in the sample input and is terminated with a "q" */ /* returns the created roster */ /* Type your code here */ } public static void main(String[] args) { Roster course = getInput(); course.display(); course.dislayScores(); }} public class Student { String id; int score; public Student(String id, int score) { /* Student Employee */ /* Type your code here */ } public String getID() { /* returns student's id */...arrow_forward
- StringFun.java import java.util.Scanner; // Needed for the Scanner class 2 3 /** Add a class comment and @tags 4 5 */ 6 7 public class StringFun { /** * @param args not used 8 9 10 11 12 public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Please enter your first name: "); 13 14 15 16 17 18 System.out.print("Please enter your last name: "); 19 20 21 //Output the welcome message with name 22 23 24 //Output the length of the name 25 26 27 //Output the username 28 29 30 //Output the initials 31 32 33 //Find and output the first name with switched characters 34 //All Done! } } 35 36 37arrow_forwardPRACTICE CODE import java.util.TimerTask;import org.firmata4j.ssd1306.MonochromeCanvas;import org.firmata4j.ssd1306.SSD1306;public class CountTask extends TimerTask {private int countValue = 10;private final SSD1306 theOledObject;public CountTask(SSD1306 aDisplayObject) {theOledObject = aDisplayObject;}@Overridepublic void run() {for (int j = 0; j <= 3; j++) {theOledObject.getCanvas().clear();theOledObject.getCanvas().setTextsize(1);theOledObject.getCanvas().drawString(0, 0, "Hello");theOledObject.display();try {Thread.sleep(2000);} catch (InterruptedException e) {throw new RuntimeException(e);}theOledObject.clear();theOledObject.getCanvas().setTextsize(1);theOledObject.getCanvas().drawString(0, 0, "My name is ");theOledObject.display();try {Thread.sleep(2000);} catch (InterruptedException e) {throw new RuntimeException(e);}while (true) {for (int i = 10; i >= 0; i--)...arrow_forwardImplement the following in the .NET Console App. Write the Bus class. A Bus has a length, a color, and a number of wheels. a. Implement data fields using auto-implemented Properies b. Include 3 constructors: default, the one that receives the Bus length, color and a number of wheels as input (utilize the Properties) and the Constructor that takes the Bus number (an integer) as input.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education