Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
Related questions
Question
Can you please write the follwing in Java.
You will implement this program in a specific way in order to gain some experience with loops, arrays and array lists.
- Use an array of strings to store the 4 strings listed in the description.
- Use a do-while loop for your 'game engine'. This means the game starts once the user enters money. The decision to stop occurs at the bottom of the loop. The do-while loop keeps going until the user quits, or there is no money left. The pseudocode for this 'game engine' is shown below:
- determine the fruits to display (step 3 below) and print them
- determine if there are 3 or 4 of the same image
- display the results
- update the customer balance as necessary
- prompt to play or quit
- continue loop if customer wants to play and there's money for another game.
- Use the Random class to generate a random number between 0 and 3. This random number will be an index into the array of strings. Add the string at that index to an ArrayList. You'll have to do this four times. When done, your ArrayList will contain 4 strings that represent randomly selected fruit images.
- Write a custom method that is called within your do-while loop. This method will accept the array list as a parameter, and it will return an integer that represents the number of times an 'fruit' appeared in the array list.
- Inside this method, use the frequency method from the Collections class to determine how many times a particular value is in a ArrayList. You'll have to call Collections.frequency for each image to get the counts by image. You can see an example of using this method on page 794 in your text. Note that this is an exception to our rule about using just the techniques in our chapters because I want you to be aware of the Collections class and how it can be helpful in certain situations.
- If your custom method returns a three, then add 2ドル to the balance. If it returns a four, then add 10ドル to the customer's balance.
- Your code should display the contents of the arraylist on the same line with spaces between them.
- Your code should display the results of the play -- see sample output -- and the current balance.
- At the bottom of the do-while loop, prompt the user if they want to continue to play (P) or to quit (Q). Case should not matter. It's OK if the user enters a character other than those two characters. Treat anything other than a 'Q' as a play.
Sample Output
Enter dollar amount to play ==> 5
Apple Apple Orange Orange
<< Not a winner this time >>
Balance is: 4ドル
Play Again (P) or Quit (Q) p
Banana Banana Orange Cherry
<< Not a winner this time >>
Balance is: 3ドル
Play Again (P) or Quit (Q) p
Banana Apple Banana Banana
<< You matched 3! That's 2ドル >>
Balance is: 5ドル
Play Again (P) or Quit (Q) q
Thanks for playing! Cash Balance is 5ドル
Expert Solution
Check MarkThis question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
bartleby
This is a popular solution
bartleby
Trending nowThis is a popular solution!
bartleby
Step by stepSolved in 5 steps with 4 images
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
- Make sure each program has at least one method in addition to its driver method(main). Or use one driver main method and write method(s) for each of the program. Write a java program using a two dimensional array and store a 10X10 multiplication table results in it. Apply a nested loop to do this. Then display the content of this same array when the user press 5 on the keyboard. Write one method to populate the array and another method to display its content.arrow_forwardWrite a program that compares several Strings using the compareTo() method. You should display the Strings and display the integer that compareTo() gives you. You must have five examples which result in a number less than 0, five examples which result in a number greater than 0, and two examples which give you exactly 0. This means you need a total of twelve examples. You may not just flip the Strings around; you must have twelve different examples. Here's an example: System.out.print("Comparing \"axe\" with \"dog\" produces "); int i = "axe".compareTo("dog"); System.out.println(i); System.out.print("Comparing \"applebee's\" with \"apple\" produces "); System.out.println( "applebee's".compareTo("apple") ); Comparing "axe" with "dog" produces -3 Comparing "applebee's" with "apple" produces 5 Make a program that asks for the last name of the user. Depending on their last name, make a statement about how long they have to wait during roll call. You need to use else ifs to make sure...arrow_forwardMust be done in Python, please helparrow_forward
- Could use some assistance on this Java exercise. Loops have proven to be quite challenging for me so any clarity on how/steps to complete this problem would be seriously appreciated.arrow_forwardCan someone help me set up this code. I am very confused. All information is in the photos. There is also a template but I don’t know how to use it (if you would like to see the template contact me it won’t let me add more than 2 photos). Please please help! The instructions are on the photos as well.arrow_forwardin javaarrow_forward
- Write the method print that receives a String array as a parameter and prints one string per line. Use the method header: public static void print(String[] array)arrow_forwardModify songVerse to play "The Name Game" (see OxfordDictionaries.com), by replacing "(Name)" with userName but without the first letter.Ex: If userName = "Katie" and songVerse = "Banana-fana fo-f(Name)!", the program prints:Banana-fana fo-fatie! Ex: If userName = "Katie" and songVerse = "Fee fi mo-m(Name)", the program prints:Fee fi mo-matie Note: You may assume songVerse will always contain the substring "(Name)" #include <iostream>#include <string>using namespace std; int main() {string userName;string songVerse; getline(cin, userName);userName = userName.substr(1, userName.size() - 1); // Remove first character getline(cin, songVerse); // Modify songVerse to replace (Name) with userName without first character /* Your solution goes here */ cout << songVerse << endl; return 0;} Please help me with this string operations problem using C++.arrow_forwardAdd a new method to ArrayTools with filter. Make this method accept a String array. Change all the Strings that are longer than 5 characters to uppercase. Write in Java and use test cases 1 & 2 as a result.arrow_forward
- Please code in java! What you will have to do is make this simple game! if you can not make the game start off with the layout and try to make the starter code! Thank you!!!arrow_forwardExecute the following statements over initially empty ArrayList myList one after another (cascade). Explain what was changed after each statement (what did it do?) myList.add("z"); ArrayList content: Your explanation (where this output came from): myList.add(0, "a"); ArrayList content: Your explanation (where this output came from): myList.add("t"); ArrayList content: Your explanation (where this output came from): myList.add(2,"w"); ArrayList content: Your explanation (where this output came from): myList.set(0,"b"); ArrayList content: Your explanation (where this output came from):arrow_forwardjava Use a loop to print the alphabet from A to Z. Print all the characters in one line, with no spaces between them. Also use another loop to print the alphabet from z to a. Print all the character in one line, with no spaces between them. Note: There will be two lines in the output. One of the uppercase letters from A to Z, and a second line for the lowercase letter from z to a.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
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