Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have provided my code below. If you were to run it you can see that nothing is passed into my method called upperLower(String str2).

I have provided my code below. If you were to run it you can see that nothing is passed into my method called upperLower(String str2). My guess is that since my first method length(String name) has a same parameter type, it doesn't allow for me to pass a String into another method. I want it to be able to pass in the new String that the user enters, if you can please help me with that. I feel like I'm missing an important concept. Thanks I do rate with up votes!

import java.util.Scanner; public class stringClass { //Create task 1 static void length(String name) { int length = name.length(); System.out.println("Task #1"); System.out.println("Length: " + length + " "); } //Create task 2 static void concat(String first, String second) { System.out.println("Task #2"); System.out.println("The concat is: " + first.concat(second) + " "); } //Create task 3 static void substring(String str1, int start, int end) { System.out.println("Task #3"); System.out.println("The substring is: " + str1.substring(start, end) + " "); } //Create task 4 static void upperLower(String str2) { System.out.println("Task #4"); System.out.println("Lowercase: " + str2.toLowerCase()); System.out.println("Uppercase: " + str2.toUpperCase() + " "); } //Create task 5 static void charAt(String str3, int index) { System.out.println("Task #5"); System.out.println("The character at index " + index + " is " + str3.charAt(index) + " "); } public static void main(String[] args) { //Create the scanner Scanner sc = new Scanner(System.in); //Prompt the user for a string System.out.println("Enter your full name: "); String name = sc.nextLine(); length(name); //Call task #1 //Ask for two separate strings System.out.println("Enter first name: "); String firstName = sc.nextLine(); System.out.println("Enter second name: "); String secondName = sc.nextLine(); concat(firstName, secondName); //Call task #2 //Ask for a new string, starting index, and ending index System.out.println("Enter a new string: "); String str1 = sc.nextLine(); System.out.println("Enter a starting index within the word: "); int startingIndex = sc.nextInt(); //Create input validation while(startingIndex < 0 || startingIndex > str1.length()) { System.out.println("ERROR! Please enter a valid index: "); startingIndex = sc.nextInt(); } System.out.println("Enter an ending index within the word: "); int endingIndex = sc.nextInt(); while(endingIndex < startingIndex || endingIndex > str1.length()) { System.out.println("ERROR! Please enter a valid index: "); endingIndex = sc.nextInt(); } substring(str1, startingIndex, endingIndex); //Call task #3 //Ask the user for string System.out.println("Please enter a new string: "); String str2 = sc.nextLine(); upperLower(str2); //Call task #4 //Ask the user for string and index within the string System.out.println("Please enter a new string: "); String str3 = sc.nextLine(); System.out.println("Enter an index within the string: "); int index = sc.nextInt(); while(index > str3.length() || index < 0) { System.out.println("ERROR! Please enter a valid index: "); index = sc.nextInt(); } charAt(str3, index); //Call task #5 } }

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_2

Step: 3

blur-text-image_3

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

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions