Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 4: (HAS TWO parts) Have a project called Lotto and create a class called Lotto. From main call two void methods lottoNumFirstname and lottoStrFirstname.

Assignment 4: (HAS TWO parts) Have a project called Lotto and create a class called Lotto. From main call two void methods lottoNumFirstname and lottoStrFirstname. Both methods take no arguments and return no values. First method should handle Question 1 from below and second method should handle Question 2 from below. ( 10 points ) Question 1 (60 points) (Extension of the problem we did in class ) Write a method lottoNumFirstname that takes in a winning lottery of a three-digit number (selected by random number generator ), prompts the user to enter a three-digit number, and determines whether the user wins according to the following rule. Please use a solution that includes numbers only and no strings: If the user input matches the lottery in exact order, the award is $10,000. If the digits in the user input is reverse of the digits in the lottery number, the award is $7,000. For example lottery number 234 and guess number of 432 ( which is in reverse order) If two continuous digits in the user input match two continuous digits in the lottery number, the award is $3,000. For example lottery number 234 and guess number of 235 or 534. But for lottery number 234 guess number of 254 does not work. ( Only if continuous.) In all other cases print Sorry play again. For example lottery number 234 and guess number of 965 or 278 Result need to be formatted using printf. Question 2: (30 points) Method 2: lottoStrFirstname Same problem as above. But redo where your pick number is a string of three digits and the Winning number is a three digit number generated randomly converted into a string. You can reuse the code from the above problem and the problem we did in class but use all string operations instead of integer operations. The user wins according to the following rule: If the user input matches the lottery in exact order, the award is $10,000. If the digits in the user input is reverse of the digits in the lottery number, the award is $7,000. For example lottery number 234 and guess number of 432 ( which is in reverse order) If two continuous digits in the user input match two continuous digits in the lottery number, the award is $3,000. For example lottery number 234 and guess number of 235 or 534.

But for lottery number 234 guess number of 254 does not work. ( Only if continuous.) In all other cases print Sorry play again. For example lottery number 234 and guess number of 965 or 278 Result need to be formatted using printf. As usual submit your whole project in one zip file.

Code for reference

import java.util.Scanner; public class LotteryStr { public static void main( String[] args) { System.out.println("Please enter a two digit number between 10 & 99: "); Scanner inp = new Scanner(System.in); String userStr = inp.next(); System.out.println("User Number is: " + userStr); //random function generates a number between 0 and 0.999999999 double randomNum = Math.random(); int lotteryNum = (int)(10 + 90 * randomNum); System.out.println("Lottery Number is: " + lotteryNum); String lottStr = Integer.toString(lotteryNum); double lottery = 0.0; String msg; char lottX = lottStr.charAt(0); char lottY = lottStr.charAt(1); char userX = userStr.charAt(0); char userY = userStr.charAt(1); /* * If user pick and lottery pick is the same then you win 10,000$ * If numbers are in reverse its 5000$ * If one number matches its 1000$ */ if( lottStr.equals(userStr)) { lottery = 10000.00; msg = "You are lucky. You won 10K."; } else if(lottX == userY && lottY == userX) { lottery = 5000.00; msg = "You are almost there. You won 5K."; } else if( (lottX == userX) || (lottX == userY) || (lottY == userX) || (lottY == userY) ) { lottery = 1000.00; msg = " You won 1000$."; } else msg = "Better Luck Next Time"; System.out.println("You won " + lottery + "\t" + msg); } }

Reference 2

import java.util.Scanner; public class Lottery { public static void main( String[] args) { System.out.println("Please enter a two digit number between 10 & 99: "); Scanner inp = new Scanner(System.in); int userNum = inp.nextInt(); System.out.println("User Number is: " + userNum); //random function generates a number between 0 and 0.999999999 double randomNum = Math.random(); int lotteryNum = (int)(10 + 90 * randomNum); System.out.println("Lottery Number is: " + lotteryNum); /* * If user pick and lottery pick is the same then you win 10,000$ * If numbers are in reverse its 5000$ * If one number matches its 1000$ */ int userX = userNum/10; int userY = userNum%10; int lottX = lotteryNum/10; int lottY = lotteryNum%10; double lottery = 0.0; String msg = ""; if( lotteryNum == userNum) { lottery = 10000.00; msg = "You are lucky. You won 10K."; } else if(lottX == userY && lottY == userX) { lottery = 5000.00; msg = "You are almost there. You won 5K."; } else if( (lottX == userX) || (lottX == userY) || (lottY == userX) || (lottY == userY) ) { lottery = 1000.00; msg = " You won 1000$."; } else msg = "Better Luck Next Time"; System.out.println("You won " + lottery + "\t" + msg); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

Explain the steps involved in training programmes.

Answered: 1 week ago

Question

What are the need and importance of training ?

Answered: 1 week ago