Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im having problem with some code and i cant figure it out, can you help me? import java.util.Scanner; import java.util.Random; // so i can use

Im having problem with some code and i cant figure it out, can you help me?

import java.util.Scanner; import java.util.Random; // so i can use the random tool

public class ChapterF422 {

public static void main(String[] args) { double putIn = 0; double won = 0; double tPutIn = 0; double tWon = 0; Random random = new Random(); //made an object for random Scanner scanner = new Scanner(System.in); System.out.println("Boot up"); putIn=scanner.nextDouble(); do //scanner might throw , might have to use try { String input; //for string char yup; do { System.out.println("Please put your money into my coin slot"); putIn = scanner.nextDouble(); //saves information tPutIn = tPutIn + putIn; //add amount to the new total int number1=random.nextInt(5); //max is five int number2=random.nextInt(5); int number3=random.nextInt(5); //these will match the pictures. for example if oranges was 1 String pic1 =" "; //for the images, cherries, oranges, plums, bells, melons, bars. String pic2 =" "; String pic3 =" "; if(number1==0) pic1="cherries"; else if( number1 ==1 ) pic1="oranges"; else if(number1==2) pic1="plums"; else if(number1 ==3) pic1="bells"; else if(number1==4) pic1="melons"; else if(number1==5) pic1="bars"; if(number2==0) pic2="cherries"; else if( number2 ==1 ) pic2="oranges"; else if(number2==2) pic2="plums"; else if(number2 ==3) pic2="bells"; else if(number2==4) pic2="melons"; else pic2="bars"; if(number3==0) pic3="cherries"; else if( number3 ==1 ) pic3="oranges"; else if(number3==2) pic3="plums"; else if(number3 ==3) pic3="bells"; else if(number3==4) pic3="melons"; else pic3="bars"; System.out.println("The pictures are " + pic1 + " , " + pic2 + " , " + pic3); if(number1==number2 && number1 == number3) won=putIn*3; //if three matched,winner winner chicken dinner. else if((number1==number2) || (number2==number3) || (number3==number1)) { won=putIn*2; } else //no match, nothing to win, pay more. won=0; System.out.println("you won " + won); tWon= tWon+won; System.out.println("would you like to play again (y/n)"); input = scanner.next(); yup = input.charAt(0); if(yup=='Y'||yup=='Y') continue; else if(yup=='N'||yup=='n') break; else System.out.println("wrong key try again"); } while(true); System.out.println("the amount of money you have wasted is " + tWon); } catch(Exception ex) { system.out.println("Error " + ex.getMessage()) } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

What is computer neworking ?

Answered: 1 week ago