Question

Each person in the group will be responsible for rewriting the code to solve ​one​ of...

Each person in the group will be responsible for rewriting the code to solve ​one​ of the original parts (celebrity names), ​without using arrays or loops.​ The purpose of this assignment is to practice Strings manipulation and String methods so full credit will only be given if you are utilizing the code for Strings (substring, charAt, compareTo, equals, etc). program Java

this was my last assigment

Take the 4th and the 5th words from part 1 and print out both of their celebrity couple names. Celebrity couples are made from taking half of the first name and combining it with the other half of the other name. The first half of the first name combines with the second half of the second name and the first half of the second name combines with the second half of the first name. Odd length names can be handled any way you wish, but all letters of both original words must be used between the two new words.

For example - Joey and Amanda would become Jonda and Amaey

// Part4- function to mix words to get celebrity couple names

    public static void mix(String a[]){

        System.out.print("Part4: ");

        // first half of 1st word + second half of 2nd word to get celebrity name of word 1

        String celeb=a[0].substring(0,a[0].length()/2)+a[1].substring(a[1].length()/2,a[1].length());

        System.out.print(celeb+" ");

        // fisrt half of 2nd word + second half of 1st word for celebrity name of word 2

        celeb=a[1].substring(0,a[1].length()/2)+a[0].substring(a[0].length()/2,a[0].length());

        System.out.print(celeb+" ");

    }

    // driver code

        public static void main(String[] args) {

                Scanner s=new Scanner(System.in);

                // words entered by user

                String words[]=new String[5];

                System.out.println("Enter 5 words:");

                for(int i=0;i<5;i++){

                    System.out.print("Word "+(i+1)+": ");

                    words[i]=s.next();

                }

                // part1 for ordering

                order(words);

               

                //part 2 for pig latin conversion

                String a[]={words[0],words[1]};

                pigLatin(a);

               

                //part 3 for reverse words

                a[0]=words[1];

                a[1]=words[2];

                reverse(a);

               

                //part 4 for mixing words

                a[0]=words[3];

                a[1]=words[4];

                mix(a);

               

        }

}

Homework Answers

Answer #1

PROGRAM :

Note: Replace the function given below with the function in your code.

public static void mix(String a[]) {
System.out.println("Part 4:");
String first = a[0];
String second = a[1];
String first_half, second_half;
int l1 = first.length();
int l2 = second.length();

// First Half
first_half = first.substring(0, l1/2) + second.substring(l2/2);

//Second Half
second_half = second.substring(0, l2/2) + first.substring(l1/2);

System.out.println(final + " " + second_half);
}

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
import java.util.Scanner; public class FindMinLength { public static int minLength(String[] array) { int minLength = array[0].length();...
import java.util.Scanner; public class FindMinLength { public static int minLength(String[] array) { int minLength = array[0].length(); for (int i = 0; i < array.length; i++) { if (array[i].length() < minLength) minLength = array[i].length(); } return minLength; } public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] strings = new String[50]; for (int i = 0; i < strings.length; i++) { System.out.print("Enter string " + (i + 1) + ": "); strings[i] = in.nextLine(); } System.out.println("Length of smallest...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){    strName = " ";    strSalary = "$0";    } public Employee(String Name, String Salary){    strName = Name;    strSalary = Salary;    } public void setName(String Name){    strName = Name;    } public void setSalary(String Salary){    strSalary = Salary;    } public String getName(){    return strName;    } public String getSalary(){    return strSalary;    } public String...
Do a theta analysis and count the number of computations it performed in each function/method of...
Do a theta analysis and count the number of computations it performed in each function/method of the following code: import java.io.*; import java.util.Scanner; class sort { int a[]; int n; long endTime ; long totalTime; long startTime; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public sort(int nn) // Constructor { a = new int[nn]; n = nn; endTime= 0; totalTime =0; startTime =0; } public static void main(String args[]) throws IOException { System.out.print("\nEnter number of students: "); int nn =...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems that need to be corrected. Your task is to complete it to course style and documentation standards CS 200 Style Guide. This project will be human graded. This class contains a set of methods. The main method contains some examples of using the methods. Figure out what each method does and style and document it appropriately. The display method is done for you and...
Please explain code 1 and code 2 for each lines code 1 public class MyQueue {...
Please explain code 1 and code 2 for each lines code 1 public class MyQueue {    public static final int DEFAULT_SIZE = 10;    private Object data[];    private int index; code 2 package test; import java.util.*; /* Class Node */ class Node { protected Object data; protected Node link; /* Constructor */ public Node() { link = null; data = 0; } /* Constructor */ public Node(Object d,Node n) { data = d; link = n; } /*...
I wrote the following java code with the eclipse ide, which is supposed to report the...
I wrote the following java code with the eclipse ide, which is supposed to report the number of guesses it took to guess the right number between one and five. Can some repost the corrected code where the variable "guess" is incremented such that the correct number of guesses is displayed? please test run the code, not just look at it in case there are other bugs that exist. import java.util.*; public class GuessingGame {    public static final int...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public void addStudent(String student) {         if (numberOfStudents == students.length) {             String[] a = new String[students.length + 1];            ...
How do I get this portion of my List Iterator code to work? This is a...
How do I get this portion of my List Iterator code to work? This is a portion of the code in the AddressBookApp that I need to work. Currently it stops at Person not found and if it makes it to the else it gives me this Exception in thread "main" java.lang.NullPointerException    at AddressBookApp.main(AddressBookApp.java:36) iter.reset(); Person findPerson = iter.findLastname("Duck"); if (findPerson == null) System.out.println("Person not found."); else findPerson.displayEntry(); findPerson = iter.findLastname("Duck"); if (findPerson == null) { System.out.println("Person not found.");...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
Use the Pythone programming language. see the #bold hashtags in the code for instructions. Also use...
Use the Pythone programming language. see the #bold hashtags in the code for instructions. Also use the website provided for an idea on how the code should be approached. please provide the code along with a screen shot of the code working with the outcome. s1 = str("abc text xyz") print("String s1 =", s1) print("First letter of s1 = ", s1[0]) print("length of s1= ", len(s1))#len for length length = len(s1) last = s1[length-1] print("Last letter = ", last) print("First...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT