Often it is necessary to validate data input by the user and repeat the request for...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Often it is necessary to validate data input by the user and repeat the request for the data in the case where the input of the user is not valid. This can be done by using a do loop, while loop, or for loop See the Lab04 04 example Assign 4.1(Lab04_01) Make a program from the following checkpoint if you cannot do it see solution. Checkpoint 4.1 What will the following program segments display? a) x = 2; y = x++; System.out.println(y); b) x = 2; System.out.println(x++); c) x = 2; System.out.println(--x); d) x = 8; y = x--; System.out.println(y); Solution: } Make a program from the following checkpoint if you cannot do it see Solution. 4.4 Write an input validation loop that asks the user to enter a number in the range of 10 through 24. public class Lab04_01 public static void main(String[] args) { { int x; Solution: int y; x-2; yx++; System.out.println(y); x = 2; System.out.println(x++); x=2; System.out.println(--x); x-8; y-x--; System.out.println(y); public class Lab4_04 //program name is case sensitive { public static void main(String[] args) { int num=15; while (num>=10 &&num<=24) { System.out.println(" number you is in the range 10 to 24"); break; } Modify the above program to read the number from keyboard. Add only the yellow lines to your Lab4_4 program. Page< 2 > of 6 C ZOOM + import java.util.Scanner; public class Lab4_04x //program name is case sensitive { public static void main(String[] args) { System.out.println("Enter a number between 10 to 24"); Scanner inNum = new Scanner(System.in); int num-inNum.nextInt(); while (num>=10 &&num<=24) { System.out.println(" number you is in the range 10 to 24"); break; } }L } Make a single program from assign4.5 and 4.6 to, if you cannot do it see the Solution 4.5 Write an input validation loop that asks the user to enter "y", "y", "N", or "n" 4.6 Write an input validation loop that asks the user to enter "Yes" or "No" Solution: public class Lab04 05 06 { public static void main(String[] args) { String str="n"; while (stria || str !="y") Assign4.5 System.out.println("You did not enter Y or y, you enter "+str): break; String stri=; while (strl!="Yes" || strl !="No") Assign4.6 System.out.println("You did not enter Yes or No, you enter "+strl); break; } } Page< 3 > of 6 C ZOOM + import java.util.Scanner; public class Assign4_5 { { public static void main(String[] args) Scanner keyboard = new Scanner(System.in); System.out.print("Enter a Y or y: "); String str keyboard.nextLine(); // read the first line char ch1 str.charAt(0); // read the first character of str string. while(chl='Y' || ch₁ =='y') L// Compar the ch1 with y or Y {{//if expression is true, print the blow line and break the loop System.out.println("You enter Y or y "+str); break; } Assign4_5.java Compile Messages GRASP Messages Run I/O Interactions Enter a Y or y: y End You enter Y or y, you enter y Clear ----jGRASP: operation complete. import java.util.Scanner; public class Assign4_5 public static void main(String[] args) { { Scanner keyboard = new Scanner(System.in); System.out.print ("Enter a Y or y: "); String str = keyboard.nextLine(); // read the first line from input char ch1 = str.charAt(0); character of str string. // read the first the chl with while ( ch1=='Y' || ch1 =='y') // compare y or Y {//if expression is true, print the blow line and break the loop System.out.println("You enter Y or y "+str); break; } Page< 4 > of 6 C ZOOM + } Optimal: If you have extra time, please practice the following. no credit If you have extra time use the Scanner keyboard= new Scanner(System.in); by declare and using the import java.util.Scanner; Assin4.1 to 4.6 using Scanner import to read in from keyboard by the API import java.util.Scanner; on the header file Inside the main usage. int num=0; Scanner keyboard= new Scanner(System.in); System.out.print("Enter a number between 10to 28: "); num = keyboard.nextInt(); Here is complete program screenshot, the checkpoint 4.1 to 4.6: Page< 5 > of 6 C ZOOM + import java.util.Scanner; public class Assig4_1To_4_6 public static void main(String[] args) { { int x =2; int y =x++; System.out.println(y); x=2; System.out.println(x++); x=2; System.out.println(--x); x=8; y =x--; System.out.println(y); int num=1; Scanner keyboard= new Scanner(System.in); System.out.print("Enter a number betweeb 10to 28: "); num = keyboard.nextInt(); while(num >=10 && num <=24) } System.out.println("You enter a number between 10 to 24 you enter "+num); break; keyboard= new Scanner(System.in); System.out.print("Enter a Y or y: "); String str keyboard.nextLine(); while(str=="Y" || str =="y") { } System.out.println("You enter Y or y, you enter "+str); break; keyboard= new Scanner(System.in); System.out.print("Enter a Yes or No: "); String str1=keyboard.nextLine(); while(stri== "Yes" || str1 == "No") { System.out.println("You enter Yes or No, you enter "+str1); break; } Page< 6 > of 6 C ZOOM + Often it is necessary to validate data input by the user and repeat the request for the data in the case where the input of the user is not valid. This can be done by using a do loop, while loop, or for loop See the Lab04 04 example Assign 4.1(Lab04_01) Make a program from the following checkpoint if you cannot do it see solution. Checkpoint 4.1 What will the following program segments display? a) x = 2; y = x++; System.out.println(y); b) x = 2; System.out.println(x++); c) x = 2; System.out.println(--x); d) x = 8; y = x--; System.out.println(y); Solution: } Make a program from the following checkpoint if you cannot do it see Solution. 4.4 Write an input validation loop that asks the user to enter a number in the range of 10 through 24. public class Lab04_01 public static void main(String[] args) { { int x; Solution: int y; x-2; yx++; System.out.println(y); x = 2; System.out.println(x++); x=2; System.out.println(--x); x-8; y-x--; System.out.println(y); public class Lab4_04 //program name is case sensitive { public static void main(String[] args) { int num=15; while (num>=10 &&num<=24) { System.out.println(" number you is in the range 10 to 24"); break; } Modify the above program to read the number from keyboard. Add only the yellow lines to your Lab4_4 program. Page< 2 > of 6 C ZOOM + import java.util.Scanner; public class Lab4_04x //program name is case sensitive { public static void main(String[] args) { System.out.println("Enter a number between 10 to 24"); Scanner inNum = new Scanner(System.in); int num-inNum.nextInt(); while (num>=10 &&num<=24) { System.out.println(" number you is in the range 10 to 24"); break; } }L } Make a single program from assign4.5 and 4.6 to, if you cannot do it see the Solution 4.5 Write an input validation loop that asks the user to enter "y", "y", "N", or "n" 4.6 Write an input validation loop that asks the user to enter "Yes" or "No" Solution: public class Lab04 05 06 { public static void main(String[] args) { String str="n"; while (stria || str !="y") Assign4.5 System.out.println("You did not enter Y or y, you enter "+str): break; String stri=; while (strl!="Yes" || strl !="No") Assign4.6 System.out.println("You did not enter Yes or No, you enter "+strl); break; } } Page< 3 > of 6 C ZOOM + import java.util.Scanner; public class Assign4_5 { { public static void main(String[] args) Scanner keyboard = new Scanner(System.in); System.out.print("Enter a Y or y: "); String str keyboard.nextLine(); // read the first line char ch1 str.charAt(0); // read the first character of str string. while(chl='Y' || ch₁ =='y') L// Compar the ch1 with y or Y {{//if expression is true, print the blow line and break the loop System.out.println("You enter Y or y "+str); break; } Assign4_5.java Compile Messages GRASP Messages Run I/O Interactions Enter a Y or y: y End You enter Y or y, you enter y Clear ----jGRASP: operation complete. import java.util.Scanner; public class Assign4_5 public static void main(String[] args) { { Scanner keyboard = new Scanner(System.in); System.out.print ("Enter a Y or y: "); String str = keyboard.nextLine(); // read the first line from input char ch1 = str.charAt(0); character of str string. // read the first the chl with while ( ch1=='Y' || ch1 =='y') // compare y or Y {//if expression is true, print the blow line and break the loop System.out.println("You enter Y or y "+str); break; } Page< 4 > of 6 C ZOOM + } Optimal: If you have extra time, please practice the following. no credit If you have extra time use the Scanner keyboard= new Scanner(System.in); by declare and using the import java.util.Scanner; Assin4.1 to 4.6 using Scanner import to read in from keyboard by the API import java.util.Scanner; on the header file Inside the main usage. int num=0; Scanner keyboard= new Scanner(System.in); System.out.print("Enter a number between 10to 28: "); num = keyboard.nextInt(); Here is complete program screenshot, the checkpoint 4.1 to 4.6: Page< 5 > of 6 C ZOOM + import java.util.Scanner; public class Assig4_1To_4_6 public static void main(String[] args) { { int x =2; int y =x++; System.out.println(y); x=2; System.out.println(x++); x=2; System.out.println(--x); x=8; y =x--; System.out.println(y); int num=1; Scanner keyboard= new Scanner(System.in); System.out.print("Enter a number betweeb 10to 28: "); num = keyboard.nextInt(); while(num >=10 && num <=24) } System.out.println("You enter a number between 10 to 24 you enter "+num); break; keyboard= new Scanner(System.in); System.out.print("Enter a Y or y: "); String str keyboard.nextLine(); while(str=="Y" || str =="y") { } System.out.println("You enter Y or y, you enter "+str); break; keyboard= new Scanner(System.in); System.out.print("Enter a Yes or No: "); String str1=keyboard.nextLine(); while(stri== "Yes" || str1 == "No") { System.out.println("You enter Yes or No, you enter "+str1); break; } Page< 6 > of 6 C ZOOM +
Expert Answer:
Answer rating: 100% (QA)
Lets break it down step by step Understanding the Checkpoints a x 2 y x Systemoutprintlny In this se... View the full answer
Related Book For
Smith and Roberson Business Law
ISBN: 978-0538473637
15th Edition
Authors: Richard A. Mann, Barry S. Roberts
Posted Date:
Students also viewed these programming questions
-
#1. Solve EXAMPLE 1.1 using segment AC, after determining the support reactions at A. 270 N/m A C 6 m 3 m B
-
Let r and s be solutions to the quadratic equation x 2 b x + c = 0. For n N, define d0 = 0 d1 = r s dn = b dn1 c dn2 (n 2) Prove that dn = r n s n for all n N. [4 marks] (b) Recall that a commutative...
-
do the following,..... Write program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. Create program that takes in user input...
-
An LNC can detect alterations in the record by Select one: a. Examining notes written in the margin b. Looking through late entries for detailed explanations c. Finding a doctor's explanation that is...
-
Find the probabilities in Problem by referring to the following tree diagram and using Bayes' formula. Round answers to three decimal places P(V|Cʹ) UV
-
Repeat Worked-Out Problem 21.3, but assume instead that the salesperson's personal cost is C(H) = 1,000 + 4H2. In addition, while each car generates a profit of $1,000, assume that the dealership's...
-
Evaluate the merits of the following statement: Enforcement is a major issue in ROSCAs, yet ROSCAs do not easily fall apart in practice. Explain why.
-
In 2019, its first year of operations, Regal Department Store sells $250,000 of gift certificates redeemable for store merchandise that expire one year after their issuance. With a high degree of...
-
One angle of a triangle measures 52 more than the smallest, while a third angle is twice the smallest. Find the measure of each angle. The triangle has angles of degrees.
-
In one-hundred words or less using Richard Daft and Robert Lengel's Media Richness Theory, define the theory then explain a situation where the inappropriate medium was used by YOU and what would...
-
The adjusted trial balance for China Tea Company at December 31, 2024, is presented below: Cash Accounts receivable. Prepaid rent Inventory Equipment Accumulated depreciation Accounts payable Notes...
-
What are the major internal audit activities identified in the Institute of Internal Auditors' Statement of Responsibilities of Internal Auditors!
-
Briefly describe the auditor's strategy when applying probability-proportional-tosize sampling.
-
Why is probability-proportional-to-size sampling most appropriate when an auditor desires testing for material overstatements?
-
Under what conditions would an auditor choose a nonstatistical sampling plan in substantive tests of details?
-
Briefly describe the auditor's strategy when applying mean-per-unit (MPU) estimation.
-
E4-14 (Algo) Assigning Costs Using Traditional System, ABC System [LO 4-1, 4-3, 4-4, 4-5] Julio produces two types of calculator, standard and deluxe. The company is currently using a traditional...
-
1. Use these cost, revenue, and probability estimates along with the decision tree to identify the best decision strategy for Trendy's Pies. 2. Suppose that Trendy is concerned about her probability...
-
Explain what trade secrets protect and how they may be infringed.
-
Pursuant to a long-standing oral agreement, a print shop manufactured and delivered written materials designed by the buyer for the buyers use and sale. After the buyers death, the executor of her...
-
This is an action by purchasers of 5 percent convertible subordinated fifteen year debentures of BarChris Construction Corporation (BarChris). * * * The action is brought under Section 11 of the...
-
Core Petroleum started its oil and gas exploration and production business in 2015. During the years 2015 and 2016, the company provided the following information relating to leases located both in...
-
The Clarence Oil Company provides the following information for the year ended December 31, 2017: REQUIRED: a. Prepare a ceiling test and an entry, if necessary, for the write-off of capitalized...
-
The Jumper Oil Corporation incurs unproved property (Lease A) costs of $60,000 on April 1, 2015. An 8% loan is obtained on April 1, 2015 for $500,000 to finance a drilling program. Jumper started a...
Study smarter with the SolutionInn App