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...
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....
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...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called keys with other objects called values. It is implemented as a Java class that uses arrays internally. 1. Theory. A map is a set of key-value pairs. Each key is said to be associated with its corresponding value, so there is at most one pair in the set with a given key. You can perform the following operations on maps. You can test if...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to the method header that will be a boolean variable: public boolean add(T newEntry, boolean sorted) The modification to the add method will makeit possible toadd new entriesto the beginning of the list, as it does now, but also to add new entries in sorted order. The sorted parameter if set to false will result in the existing functionality being executed (it will add the...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • 3. A fair coin is flipped 4 times. (a) What is the probability that the third...
    asked 28 minutes ago
  • An engineer wants to know if the mean strengths of three different concrete mix designs differ...
    asked 28 minutes ago
  • The National Football League (NFL) records a variety of performance data for individuals and teams. To...
    asked 38 minutes ago
  • Associated Strategies obtained significant influence over Cece Corporation by buying 30% of Cece’s 50,000 outstanding shares...
    asked 39 minutes ago
  • A survey of 25 randomly selected customers found the ages shown​ (in years). The mean is...
    asked 43 minutes ago
  • (1)         For this discussion, I would like for you to identify and describe two out of...
    asked 44 minutes ago
  • Determine the open intervals on which the graph is concave upward or concave downward. (Enter your...
    asked 45 minutes ago
  • 9- What is the most widely used technique for determining the best combination of debt and...
    asked 45 minutes ago
  • Katsumoto Inc. (Katsumoto) manufactures and sells collectible swords. Katsumoto currently operates at 80% of its 15,000-unit...
    asked 47 minutes ago
  • A researcher wishes to estimate the percentage of adults who support abolishing the penny. What size...
    asked 54 minutes ago
  • Discuss why the longer-term generation of positive free cash flow is important to the providers of...
    asked 59 minutes ago
  • The three main areas for memory in the brain involve the Hippocampus, the Basal Ganglia, and...
    asked 1 hour ago