Name your project and class Lab5. Using JOptionPane, write a program that prompt
ID: 3657652 • Letter: N
Question
Name your project and class Lab5. Using JOptionPane, write a program that prompts the user whether they want to specify a number between 1 and 7 or have the system generate a random number in that range. If the user wants to specify the number, prompt them for it and verify its validity. Otherwise generate a random number between 1 and 7. Display the number to the user. Once you have the number, open the lab5.txt file that you copied earlier and read that numbered record; for example, if the number was 3, read the third sentence from the file. Display the sentence to the user. Finally, reverse the order of the sentence; that is, take the last letter of the sentence and make it the first, proceeding all through the sentence. Display the reversed sentence.Explanation / Answer
package cramster.com; import java.io.File; import java.io.FileNotFoundException; import java.util.Random; import java.util.Scanner; import javax.swing.JOptionPane; public class Cramsterlab5 { public static void main(String[] args) { int choice = JOptionPane.showConfirmDialog(null, "Do you want to enter a number?"); int randomNumber = 0; switch(choice) { case 0: while(true) { randomNumber = Integer.parseInt( JOptionPane.showInputDialog(null,"Enter a number between 1 to 7 : ")); if(randomNumber >0 && randomNumberRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.