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

1. A user must be able to enter first name and last name, in that order, and you

ID: 670112 • Letter: 1

Question

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

Explanation / Answer

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;

public class Lab4LastNameFI {
   public static void main(String[] args) {
       try {
           String fn,ln;
           int r1,r2,r3,r4,r5;
           Sting ans="aa";
           DataInputStream o = new DataInputStream(system.in);
Random r = new Random();
           System.out.println("enter Data continuosly and at end type Done to finish");
           while(ans!="Done")
           {

           System.out.print("Enter First Name");
           fn=o.readLine();
           System.out.print("Enter Last Name");
           ln=o.readLine();
           r1=r.nextInt(100);
           r2=r.nextInt(100);
           r3=r.nextInt(100);
           r4=r.nextInt(100);
           r5=r.nextInt(100);
           String content = fn +" " + ln +":"+r1.toString+r2.toString+r3.toString()+r4.toString()+r5.toString;

           File file = new File("LotteryEntrants.txt");

           // if file doesnt exists, then create it
           if (!file.exists()) {
               file.createNewFile();
           }

           FileWriter fw = new FileWriter(file.getAbsoluteFile());
           BufferedWriter bw = new BufferedWriter(fw);
           bw.write(content);
           }
           int win;
           win=r.nextInt(100);
           bw.write(win.toString());
           bw.close();


       } catch (IOException e) {
           e.printStackTrace();
       }
   }
}