Question

Practice manipulating an object by calling its methods. Complete the class Homework1 class using String methods....

Practice manipulating an object by calling its methods.

Complete the class Homework1 class using String methods. Remember that all the String methods are accessors. They do not change the original String. If you want to apply multiple methods to a String, you will need to save the return value in a variable.

Complete the class by doing the following:
+ Print the word in lowercase
+ Replace "e" with "3" (Use the unmodified variable word)
+ Print the changed word
+ In the changed word, replace: "t" with "7"
+ Print the changed word
+ In this newest changed word, replace: "L" with "1" (uppercase L with the number 1). Then, print the final changed word (with all the replacements)
+Print the length of the word

The code to print the original word is already included for you. Do not change that statement. You will need to use the replace() method multiple times. Then print the final String. Remember that replace is an accessor method; It returns the changed version of the String. If you want to do something with the returned String - like use replace() on it again - you need to save the return value in a variable.

Given code is below:

public class Homework1
{
   public static void main(String[] args)
   {
      String word = "CoLton";
    
      // Add your code here
      System.out.println("original word: " + word);
   }
}

Homework Answers

Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

// Homework1.java

public class Homework1 {

      public static void main(String[] args) {

            String word = "CoLton";

            System.out.println("original word: " + word);

            // printing word in lower case without saving

            System.out.println("word in lower case: " + word.toLowerCase());

            // replacing 'e' with '3' and storing in word itself

            word = word.replace('e', '3');

            // printing updated word. since 'CoLton' does not have 'e', this would

            // print 'CoLton' itself

            System.out.println("changed word: " + word);

            // changing 't' with '7' and storing updated value in word itself

            word = word.replace('t', '7');

            // will print 'CoL7on'

            System.out.println("changed word: " + word);

            // changing 'L' to '1'

            word = word.replace('L', '1');

            // printing word for one last time

            System.out.println("final word: " + word); // Co17on

            // displaying length of the word

            System.out.println("length of the word: " + word.length());

      }

}

/*OUTPUT*/

original word: CoLton

word in lower case: colton

changed word: CoLton

changed word: CoL7on

final word: Co17on

length of the word: 6

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java Programming In this lab students continue to write programs using multiple classes. By the end...
Java Programming In this lab students continue to write programs using multiple classes. By the end of this lab, students should be able to Write classes that use arrays and ArrayLists of objects as instance variables Write methods that process arrays and ArrayLists of objects Write getter and setter methods for instance variables Write methods using object parameters and primitive types Question- class StringSet. A StringSet object is given a series of up to 10 String objects. It stores these...
Complete the implementation of the Card class. The two methods that you need to complete are...
Complete the implementation of the Card class. The two methods that you need to complete are compareTo and equals. CopareTo API: Compares this card to another card for order. This method imposes the following order on cards: Cards are first compared by rank. If the rank of this card is less than the rank of the other card then -1 is returned. If the rank of this card is greater than the rank of the other card then 1 is...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(),...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(), and isEmpty(). For this assignment, enqueue() will be implemented in an unusual manner. That is, in the version of enqueue() we will use, if the element being processed is already in the queue then the element will not be enqueued and the equivalent element already in the queue will be placed at the end of the queue. Additionally, you must implement a circular queue....
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...
main The main method instantiates an ArrayList object, using the Car class. So, the ArrayList will...
main The main method instantiates an ArrayList object, using the Car class. So, the ArrayList will be filled with Car objects. It will call the displayMenu method to display the menu. Use a sentinel-controlled loop to read the user’s choice from stdin, call the appropriate method based on their choice, and redisplay the menu by calling displayMenu. Be sure to use the most appropriate statement for this type of repetition. displayMenu Parameters:             none Return value:          none Be sure to use...
This must be answered not advance methods, focusing on String method. We are working on Ch...
This must be answered not advance methods, focusing on String method. We are working on Ch 9 in Think Java 1st Ed.I need the program to be bare bones and the coding need to be done the long way with no advanced code. in this lab you will have two methods with headings: - public static int countNumberSigns(String tweetText) - public static int countHashtags(String tweetText) 'String tweetText' means the method is expectiong a string value as an input to it....
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class Zillion implements a decimal counter that allows numbers with an effectively infinite number of digits. Of course the number of digits isn’t really infinite, since it is bounded by the amount of memory in your computer, but it can be very large. 1. Examples. Here are some examples of how your class Zillion must work. I’ll first create an instance of Zillion. The string...
TrackMinMax For this lab, you will create a generic version of the IntTrackMinMax class you wrote...
TrackMinMax For this lab, you will create a generic version of the IntTrackMinMax class you wrote in a previous lab, called TrackMinMax. The API is: Function Signature Description constructor TrackMinMax() constructor check void check(T i) compares i to the current minimum and maximum values and updates them accordingly getMin T getMin() returns the minimum value provided to check() so far getMax T getMax() returns the maximum value provided to check() so far toString String toString() returns the string "[min,max]" As...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class and a Node class (please name your classes exactly ​as I did here). Please follow the below specifications for the two classes. Node.cpp ● This must be a generic class. ● Should contain a generic member variable that holds the nodes value. ● Should contain a next and prev Node* as denoted here. ● All member variables should be private. ● Use public and...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT