Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction In this lab, you will use the String class methods to manipulate strings. Identification String Your ID String will be put into it's own

Introduction

In this lab, you will use the String class methods to manipulate strings.

Identification String

Your ID String will be put into it's own separate method call idString(). We haven't covered methods yet so simply find the space in the program template and fill in the corresponding information. For example, your instructor's return statement would be: return "Strings, Patty Kraft";

Task

You will write a program that ensures the user enters the city and state in proper capitalization. For simplicity, we will only work with cities that are spelled with one word. Suppose the user enters,

Chicago, il 

This will be changed by your program to

Chicago, IL 

Plan your approach

Look at the following possible entries and think, in terms of strings, how to correct it.

  • chicago, IL
  • ChicaGO, IL
  • Chicago, Il
  • Chicago, iL

Seriously, did you try to work out a solution? We know that:

  • the first character and the state abbreviation should be capitalized
  • the rest of the city name (up to the comma) should be lowercase

String class methods we will find helpful are: charAt(), indexOf(), toUpperCase(), toLowerCase(), substring().

image text in transcribed

image text in transcribed

image text in transcribed

8.15 Lab 4b: String and Substring Introduction In this lab, you will use the String class methods to manipulate strings. Identification String Your ID String will be put into it's own separate method call idString(). We haven't covered methods yet so simply find the space in the program template and fill in the corresponding information. For example, your instructor's return statement would be: return "Strings, Patty Kraft": Task You will write a program that ensures the user enters the city and state in proper capitalization. For simplicity, we will only work with cities that are spelled with one word. Suppose the user enters, Chicago, il This will be changed by your program to Chicago, IL Plan your approach Look at the following possible entries and think, in terms of strings, how to correct it. chicago, IL Chicago, IL Chicago, Il Chicago, IL Seriously, did you try to work out a solution? We know that: the first character and the state abbreviation should be capitalized the rest of the city name (up to the comma) should be lowercase String class methods we will find helpful are: charAt(), indexOf(), toUpperCase(), to LowerCase(), substring(). 304400.1000192 LAB ACTIVITY 8.15.1: Lab 4b: String and Substring 0/10 Strings.java Load default template... i import java.util.Scanner; 2 3 public class Strings { 4 5 public static String idString() { 6 6 // FIX ME: Replace First Name with your first name 7 and replace LastName with your last name. 8 8 return "Strings, FirstName LastName"; 9 } 10 11 public static void main(String[] args) { 12 System.out.print("Enter a city, state: "); 13 Scanner scan = new Scanner(System.in); 14 15 // FIXME: Get the next line 16 String place - 17 18 // FIXME: Make place all uppercase Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the programs output in the second box Enter program input (optional) If your code requires input values, provide them here. LAB ACTIVITY 8.15.1: Lab 4b: String and Substring 0/10 Strings.java Load default template... 1 import java.util.Scanner; 2 3 public class Strings / 1 5 public static String idString() { 6 // FIX ME: Replace FirstName with your first name 7 and replace Last Name with your last name. 8 8 return "Strings, FirstName LastName"; 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 25 27 28 29 30 31 32 33 34 35 } public static void main(String[] args) { System.out.print("Enter a city, state: "); Scanner scan = new Scanner(System.in); // FIXME: Get the next line String place = // FIXME: Make place all uppercase, String upPlace = // FIXME: Get rest of city name using substring of upplace from 1 up to indexOf('. // HINT: Use two argument method of substring(startIndex, endAtBut DoNot Include Index) String rest - // FIXME: Create city name from first char of upPlace, concatenated with rest in lowercase String city - // FIXME: Extrace the state substring from upPlace from indexOf(',') plus 2, // HINT: Use one argument method of substring(startIndex) String state- // FIXME: Print city comma state that is non correctly capitalized! }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago