Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is just for intro class. 1. A user must be able to enter first name and las

ID: 670190 • Letter: T

Question

This is just for intro class.

1. A user must be able to enter first name and last name, in that order, and you assign five random lottery numbers to that person and let the user enter names until they want to quit. You must tell them what they have to type to end the program. You must write all valid entries with “lastName, firstName: “ and assigned lottery numbers to a file. If the user enters no name or only puts a first name tell the user it is not a valid entry, do not write to the file, and prompt again. When the user quits write the winning lottery numbers to the file.

Requirements:

* Prompt user for first name and last name in that order

* Things like sentinel values and the number of lottery numbers assigned should be able to be modified easily with one line of code

* Verify user entered both first and last name prior to assigning lottery numbers and writing to file

* Notify the user of invalid entries and continue prompting

* Test your program with entries like “”, “Andy”, “Andy “

* Lottery numbers are integers randomly assigned between 1-100

* Write “lastname, firstname: x x x x x” to file for valid entries

* Once the user is done write the winning lottery numbers to the file

* Your source file should be named Lab4LastNameFI.java

* Output file should be called LotteryEntrants.txt

Sample Input:

E:BoxCS007Labs>java Lab4

Please enter first name and last name for entry into lottery(type quit to end):Kathryn Blythe

Please enter first name and last name for entry into lottery(type quit to end):Angelica Grant

Please enter first name and last name for entry into lottery(type quit to end):Rich Cuddy

Please enter first name and last name for entry into lottery(type quit to end):Ryan Curran

Please enter first name and last name for entry into lottery(type quit to end):Paige Haring

Please enter first name and last name for entry into lottery(type quit to end):Andy

Andy Is not a valid entry try again

Please enter first name and last name for entry into lottery(type quit to end):quit

E:BoxCS007Labs>java Lab4

Sample Output File:

Blythe, Kathryn: 91, 20, 3, 32, 94

Grant, Angelica: 34, 71, 75, 80, 28

Cuddy, Rich: 78, 66, 14, 88, 52

Curran, Ryan: 8, 30, 54, 56, 98

Haring, Paige: 16, 79, 9, 76, 6

Winning Lottery Numbers are: 60 5 23 43 10

Explanation / Answer

import java.util.Scanner; //import scanner import java.util.Random; //import randomizer import java.io.*; //needed for throws clause public class randomLottery { public static void main(String[] args) throws IOException { String fullName; Scanner keyboard = new Scanner( System.in ); //so we can generate random numbers Random rand = new Random(); //declare a constant number of numbers final int LOTTERY_NUMBERS = 5; //Retrieve names System.out.print("Please enter a first and last name for lottery " + "entry (type 'quit' to end): "); fullName = keyboard.nextLine(); while(!fullName.contains(" ")) { System.out.print("Please enter BOTH a first and last name." + " Try Again: "); fullName = keyboard.nextLine(); } while(!fullName.contains("quit")) { //separate first/last name String[] parts = fullName.split(" "); String firstName = parts[0]; String lastName = parts[1]; //Open the file PrintWriter outputFile = new PrintWriter("LotteryEntrants.txt"); //Print the name onto the file outputFile.print(lastName + ", " + firstName + ": "); int number; for (number = 1; number
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote