
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
![اماء
the array and test for a match. You also need to set
a flag if there is a match, and then test the flag
variable to determine if you should print the "Not a
city in Michigan" message. Comments in the code
tell you where to write your statements.
Instructions
go
Ⓒ
1. Study the prewritten code to make sure you
understand it.
2. Write a loop statement that examines the names
of cities stored in the array.
3. Write code that tests for a match.
4. Write code that, when appropriate, prints the
message: "Not a city in Michigan.".
5. Execute the program using the following as
input:
Chicago
Brooklyn
Watervliet
Acme
Grading
When you have completed your program, click the
Submit button to record your score.
8 public class MichiganCities
9 {
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
1
public static void main(String args[]) throws Exception
{
EE
// Declare variables.
String inCity;
// name of city to look up in array.
// Initialized array of cities in Michigan.
String cities InMichigan[] = ["Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Sagina
"Richland", "Glenn","Midland", "Brooklyn";
boolean foundIt = false; // Flag variable.
int x;
// Loop control variable.
// Get user input.
Scanner input = new Scanner(System.in);
System.out.println("Enter the name of the city: ");
inCity = input.nextLine();
// Write your loop here.
// Write your test statement here to see if there is
// a match. Set the flag to true if city is found.
}
39
40 } // End of main() method.
41} // End of MichiganCities class.
// Test to see if city was not found to determine if
// "Not a city in Michigan" message should be printed.
System.exit(0);
Q Search
16](https://content.bartleby.com/qna-images/question/d37f1519-9bca-4c3f-95f7-bdfad11980b2/23bfa8d9-b1db-4c3b-8a6d-819e873d433d/lq3exsk_thumbnail.jpeg)
Transcribed Image Text:اماء
the array and test for a match. You also need to set
a flag if there is a match, and then test the flag
variable to determine if you should print the "Not a
city in Michigan" message. Comments in the code
tell you where to write your statements.
Instructions
go
Ⓒ
1. Study the prewritten code to make sure you
understand it.
2. Write a loop statement that examines the names
of cities stored in the array.
3. Write code that tests for a match.
4. Write code that, when appropriate, prints the
message: "Not a city in Michigan.".
5. Execute the program using the following as
input:
Chicago
Brooklyn
Watervliet
Acme
Grading
When you have completed your program, click the
Submit button to record your score.
8 public class MichiganCities
9 {
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
1
public static void main(String args[]) throws Exception
{
EE
// Declare variables.
String inCity;
// name of city to look up in array.
// Initialized array of cities in Michigan.
String cities InMichigan[] = ["Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Sagina
"Richland", "Glenn","Midland", "Brooklyn";
boolean foundIt = false; // Flag variable.
int x;
// Loop control variable.
// Get user input.
Scanner input = new Scanner(System.in);
System.out.println("Enter the name of the city: ");
inCity = input.nextLine();
// Write your loop here.
// Write your test statement here to see if there is
// a match. Set the flag to true if city is found.
}
39
40 } // End of main() method.
41} // End of MichiganCities class.
// Test to see if city was not found to determine if
// "Not a city in Michigan" message should be printed.
System.exit(0);
Q Search
16
![L06.2-Searching an Array for an Exact Match in Java
B|
YE
</>
Searching an Array for an Exact
Match
The data file provided for this lab includes the input
statements and the necessary variable declarations.
You need to use a loop to examine all the items in
the array and test for a match. You also need to set
a flag if there is a match, and then test the flag
variable to determine if you should print the "Not a
city in Michigan" message. Comments in the code
tell you where to write your statements.
f
Ⓒ
✪
Instructions
1. Study the prewritten code to make sure you
understand it.
2. Write a loop statement that examines the names
of cities stored in the array.
3. Write code that tests for a match.
4. Write code that, when appropriate, prints the
message: "Not a city in Michigan.".
5. Execute the program using the following as
input:
Chicago
Brooklyn
Watervliet
Acme
Grading
MichiganCities.java
1 // MichiganCities.java
2 // Input: Interactive.
3 // Output: Error message or nothing.
4
5
24
25
6 import java.util.Scanner;
7
8 public class MichiganCities
9 {
10 public static void main(String args[]) throws Exception
11
{
12
13
14
15
16
17
18
19
20
21
22
23
26
27
28
29
30
31
32
33
34
35
36
FH
+
// Declare variables.
String inCity;
// Initialized array of cities in Michigan.
String citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw",
"Richland", "Glenn","Midland", "Brooklyn"};
boolean foundIt = false; // Flag variable.
// Loop control variable.
int x;
}
This program prints a message for invalid cities in Michigan.
// Get user input.
Scanner input = new Scanner(System.in);
System.out.println("Enter the name of the city: ");
inCity input.nextLine();
// Write your loop here.
// Write your test statement here to see if there is
// a match. Set the flag to true if city is found.
£
Q Search
// name of city to look up in array.
// Test to see if city was not found to determine if
// "Not a city in Michigan" message should be printed.
System.exit(0);
16
Q Sear
dx
12
10/1](https://content.bartleby.com/qna-images/question/d37f1519-9bca-4c3f-95f7-bdfad11980b2/23bfa8d9-b1db-4c3b-8a6d-819e873d433d/e5jmx1_thumbnail.jpeg)
Transcribed Image Text:L06.2-Searching an Array for an Exact Match in Java
B|
YE
</>
Searching an Array for an Exact
Match
The data file provided for this lab includes the input
statements and the necessary variable declarations.
You need to use a loop to examine all the items in
the array and test for a match. You also need to set
a flag if there is a match, and then test the flag
variable to determine if you should print the "Not a
city in Michigan" message. Comments in the code
tell you where to write your statements.
f
Ⓒ
✪
Instructions
1. Study the prewritten code to make sure you
understand it.
2. Write a loop statement that examines the names
of cities stored in the array.
3. Write code that tests for a match.
4. Write code that, when appropriate, prints the
message: "Not a city in Michigan.".
5. Execute the program using the following as
input:
Chicago
Brooklyn
Watervliet
Acme
Grading
MichiganCities.java
1 // MichiganCities.java
2 // Input: Interactive.
3 // Output: Error message or nothing.
4
5
24
25
6 import java.util.Scanner;
7
8 public class MichiganCities
9 {
10 public static void main(String args[]) throws Exception
11
{
12
13
14
15
16
17
18
19
20
21
22
23
26
27
28
29
30
31
32
33
34
35
36
FH
+
// Declare variables.
String inCity;
// Initialized array of cities in Michigan.
String citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw",
"Richland", "Glenn","Midland", "Brooklyn"};
boolean foundIt = false; // Flag variable.
// Loop control variable.
int x;
}
This program prints a message for invalid cities in Michigan.
// Get user input.
Scanner input = new Scanner(System.in);
System.out.println("Enter the name of the city: ");
inCity input.nextLine();
// Write your loop here.
// Write your test statement here to see if there is
// a match. Set the flag to true if city is found.
£
Q Search
// name of city to look up in array.
// Test to see if city was not found to determine if
// "Not a city in Michigan" message should be printed.
System.exit(0);
16
Q Sear
dx
12
10/1
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- text file 80 1 2 3 100 100 100 1001 0 2 100 3 4 100 1002 2 0 4 4 100 5 1003 100 4 0 100 100 4 100100 3 4 100 0 3 3 3100 4 100 100 3 0 100 1100 100 5 4 3 100 0 2100 100 100 100 3 1 2 0 My code below. I am getting an error when trying to create my adjacency matrix. i dont know what i am doing wrong def readMatrix(inputfilename): ''' Returns a two-dimentional array created from the data in the given file. Pre: 'inputfilename' is the name of a text file whose first row contains the number of vertices in a graph and whose subsequent rows contain the rows of the adjacency matrix of the graph. ''' # Open the file f = open(inputfilename, 'r') # Read the number of vertices from the first line of the file n = int(f.readline().strip()) # Read the rest of the file stripping off the newline characters and splitting it into # a list of intger values rest = f.read().strip().split() # Create the adjacency matrix adjMat = []…arrow_forwardI need some help fixing this code. I need it to let me enter the ISBN number witht the dashes and find the check number my code is below Ill like my teachers direction as a refernce. def main():while True:print('1. Verify the check digit of an ISBN-10')print("2. verify the check digit of an ISBN-13")print("3. Convert an ISBN-10 to an ISBN-13")print('4. Convert an ISBN-13 to an ISBN-10')print('5. Exit')command = input("Enter the Command (1-5): ")if command == '5':breakelif command == '1' or command == '3':# get 10 digit inputISBN = input("Please enter the ISBN-10 number: ")ISBN = ISBN.replace('-', '')while len(ISBN) != 10:print("Please make sure you have entered a number which is exactly 10 characters long.")ISBN = input("Please enter the ISBN number: ")ISBN = ISBN.replace('-', '')print(format(ISBN))if command == '1':print(check_10_digit(ISBN))else:print(convert_10_to_13(ISBN))elif command == '2' or command == '4':# get 13 digit inputISBN = input("Please enter the 13 digit number:…arrow_forward
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education