Question

In: Computer Science

Test Your Understanding Create a JAVA package by name ClassEx2 and in the main() method of...

Test Your Understanding

Create a JAVA package by name ClassEx2 and in the main() method of
the class, assign your name to a String object and your father name to a
different String object and do the following;

Concatenate your name and your father name.

Get the length of your full name.

Find the index of any character in your full name.

Replace the occurrence of any lower case character in your full
name to capital character.

Compare your first name with your father name , display message
indicating which name is first lexicographically.

Solutions

Expert Solution

Complete code in java:-

class ClassEx2 {
   public static void main(String ... args) {
       // Creating string object of my name.
       String name = new String("Alice");
       System.out.println("My name: "+name);

       // Creating string object of my father's name.
       String fatherName = new String("John");
       System.out.println("My father's name: "+fatherName);

       // Concatenating both names.
       String fullName = name+fatherName;
       System.out.println("Full name after concatenation: "+fullName);

       // Measuring length of concatenated name.
       int len = fullName.length();
       System.out.println("Length of full name: "+len);

       // Getting index of 'e' in full name.
       int indexOfE = fullName.indexOf("e");
       System.out.println("Index of character 'e' in full name: "+indexOfE);

       // Replacing 'i' with 'I' in full name.
       fullName = fullName.replace('i', 'I');
       System.out.println("Full name after replacement of 'i' with 'I': "+fullName);

       // Comparing both names.
       int comp = name.compareTo(fatherName);
       if(comp == 0) {
           System.out.println("Both names are equal lexicographically");
       }
       else if(comp > 0) {
           System.out.println("My name is greater than my father's name laxicographically");
       }
       else {
           System.out.println("My father's name is greater than my name laxicographically");
       }
   }
}

Screenshot of output:-


Related Solutions

Create a Java class with the name (identifier) MyProgram and place it in the Questions package....
Create a Java class with the name (identifier) MyProgram and place it in the Questions package. You will need to create a main method for this class and place all of your code inside of that method. Your program should complete the following steps: - Prompt the user to enter a name for a Student. - Use the Scanner class to read in the user input and store the result in a variable. - Use the Random class to generate...
Write the code in Java: 1. Create a method that displays your name in the console....
Write the code in Java: 1. Create a method that displays your name in the console. This method is void and takes no parameters. Make an app that runs the method in response to a button press. 2. Create a version of the method in #1 that takes the text (String) to be displayed as a parameter. Allow the user to enter the text in a dialog box or text field and display that text in the console. Be sure...
In a Package called characterArray, ********JAVA CODE********** 1) Create a char array containing your full name...
In a Package called characterArray, ********JAVA CODE********** 1) Create a char array containing your full name and print it out. 2) Create an uninitialized char array and copy into it      the char array containing your full name and print it out. 3) Create a Character array and copy into it the char array containing      your full name and print it out. 4) Into the Character array, use toUpperCase() to copy the char array containing     your full name...
In Java Create a class called "TestZoo" that holds your main method. Write the code in...
In Java Create a class called "TestZoo" that holds your main method. Write the code in main to create a number of instances of the objects. Create a number of animals and assign a cage and a diet to each. Use a string to specify the diet. Create a zoo object and populate it with your animals. Declare the Animal object in zoo as Animal[] animal = new Animal[3] and add the animals into this array. Note that this zoo...
JAVA single method Loop (for beginner) Name your class LoopsFiles Create a program that reads a...
JAVA single method Loop (for beginner) Name your class LoopsFiles Create a program that reads a list of names from a source file and writes those names to a CSV file. The source file name and target CSV file name should be requested from the user The source file can have a variable number of names so your program should be dynamic enough to read as many names as needed When writing your CSV file, the first row (header row)...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of Poem objects, read in the information from PoemInfo.txt and create Poem objects to populate the ArrayList. After all data from the file is read in and the Poem objects added to the ArrayList- print the contents of the ArrayList. Paste your PoemDriver.java text (CtrlC to copy, CtrlV to paste) into the open space before. You should not change Poem.java or PoemInfo.txt. Watch your time...
Language: Java Create a TryIt.java program with a main method. You are going to use this...
Language: Java Create a TryIt.java program with a main method. You are going to use this program to demonstrate some things about how Java works. Make your methods here private, because they are not intended to be called from outside the program. For each test below, make sure that you print to the console: 1) What is being tested 2) The desired output 3) The actual output Question to be answered: Should you use == or the String method equals...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑ Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. ☑ Add a method addToCollection. In this method,...
Program in Java Create a class and name it MyArray and implement following method. * NOTE:...
Program in Java Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those. Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT