(Solved) : Exercise 1 Examine Shoppingcartjava Perform Following Use Indexof Method Get Index Space C Q36545258 . . .
Exercise 1
• Examine ShoppingCart.java.
– Perform the following:
– Use the indexOf method to get the index for the spacecharacter (” “) within custName. Assign it to spaceIdx.
– Use the substring method and spaceIdx to get the first nameportion of custName. Assign it to firstName and printfirstName.
public class ShoppingCart {
public static void main (String[] args){
String custName =”Steve Smith”;
String firstName;
int spaceIdx;
// Get the index ofthe space character (” “) in custName.
// Use the substringmethod parse out the first name and print it.
}
}
Exercise 2
Examine NameMaker.java.
• Perform the following:
– Declare String variables: firstName, middleName, lastName, andfullName
– Prompt users to enter their first, middle, and last names andread the names from the keyboard.
– Set and display the fullName as firstName+a blankchar+middleName+a blank char+lastName.
package com.example;
public class NameMaker {
public static void main(String args[])
{
}
Expert Answer
Answer to Exercise 1 Examine Shoppingcartjava Perform Following Use Indexof Method Get Index Space C Q36545258 . . .
OR