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
-
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...
-
We are in an age of growing media attention towards trans-identity. What is this? What, specifically, can we learn from Dolezal and Jenner?
-
The probability that a patient recovers from a delicate heart operation is 0.9. Of the next 100 patients having this operation, what is the probability that (a) Between 84 and 95 inclusive survive?...
-
Explain the working of domestic refrigeration system with a neat sketch?
-
Marks & Spencer, a huge retailer in the United Kingdom with sales of more than 9 billion, was troubled by its paper bureaucracy. Looked at in isolation, each document seemed reasonable, but overall a...
-
The big hope housing company uses a predetermined overhead rate to allocate overhead based on Direct Labor cost. This years budget includes Overhead equal to $500,000 and Direct Labor cost of...
-
Recently Santa Fe, New Mexico, was named one of the safest places to live in the United States. Since then, housing development projects have been springing up all around Santa Fe. Six housing...
-
3) How long did the arrow fly through the air before striking the ground? (When would h= 0 ft?) h=-32t+200t+5.75
-
Wok this Way is a famous dance studio in downtown Toronto. They are very popular and seeking to grow their busienss. As such, Wok This Way has signed a franchise agreement on May 31, 2027 to allow a...
-
You ask Alexa (a spherically symmetric speaker) to play your favorite Nickelback song. When you are standing 3.0 meters away, that sound reaches your ears at an intensity level of 50 decibels. Since...
-
1. Most aspects of development are clearly influenced by both nature and nurture. Thinking specifically about physical growth and development, describe at least one way in which nature influences...
-
How do communication strategies such as SBAR (Situation-Background. Assessment-Recommendation) promote patient safety?
-
Tawney worked as a forest firefighter for the Province of Ontario and was a member of the Initial Attack Forest Firefighting crew for a small area in the forests of Northern Ontario. The crew's job...
-
The term "stellar remnant" is used for what type of objects A) objects too small for fusion to have started in their cores objects who are too young for fusion to begin in their cores (C) objects...
-
The Zwatch Company manufactures trendy, high-quality moderately priced watches. As Zwatch's senior financial analyst, you are asked to recommend a method of inventory costing. The CFO will use your...
-
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...
-
The following actual balance sheet was prepared for Martins Musical Supplies Ltd as at 30 September 2020. At 30 September, you are also provided with the following information. 1. Sales forecasts...
-
Based on your reading of this chapter, the following job description, and the two rsums below, analyze the two applicants for the position. What are their strengths and weaknesses as highlighted by...
-
Write a rsum that you could use in your job search. As your instructor directs, a. Write a rsum for the field in which you hope to find a job. b. Write two different rsums for two different job paths...
Study smarter with the SolutionInn App