Question

Write a function that takes two string parameters which represent the names of two people and...

Write a function that takes two string parameters which represent the names of two people and returns True if the people are a "match" and False if they are not.

Determining Love

Total all the ‘L’s ‘O’s ‘V’s and ‘E’s (uppercase and lowercase) found in each of their names.

  • If the number of LOVE letters combined between both their names is odd, return True.
  • If the number of LOVE letter combined between both their names is even, return False.

* Note that this function should have NO SIDE EFFECTS - which means that the print statement should not be in the function itself, but rather in the main.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As per the question please find below the answer :-

Code in JAVA:-

import java.util.Scanner;

public class LoveMatch {

   public static boolean loveMatch(String name, String partnerName) {
       boolean match = true;
       int loveMatchCondition = 0;
       String[] nameArr = name.split("");
       String[] partnerNameArr = partnerName.split("");
       int countName = 0, countPartnerName = 0;
       for (int i = 0; i < nameArr.length; i++) {
           if (nameArr[i].equalsIgnoreCase("l") || nameArr[i].equalsIgnoreCase("o") || nameArr[i].equalsIgnoreCase("v")
                   || nameArr[i].equalsIgnoreCase("e"))
               ++countName;
       }
       for (int i = 0; i < partnerNameArr.length; i++) {
           if (partnerNameArr[i].equalsIgnoreCase("l") || partnerNameArr[i].equalsIgnoreCase("o")
                   || partnerNameArr[i].equalsIgnoreCase("v") || partnerNameArr[i].equalsIgnoreCase("e"))
               ++countPartnerName;
       }
       loveMatchCondition = countName + countPartnerName;
       if (loveMatchCondition % 2 == 0)
           match = false;
       else
           match = true;

       return match;
   }

   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       String personOne, personTwo;
       personOne = sc.nextLine();
       personTwo = sc.nextLine();
       if (loveMatch(personOne, personTwo)) {
           System.out.println("True");
       } else
           System.out.println("False");

       sc.close();
   }

}

Thank You!!!

Add a comment
Know the answer?
Add Answer to:
Write a function that takes two string parameters which represent the names of two people and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function updateAges(names, ages) that takes as parameters a list of names of people whose...

    Write a function updateAges(names, ages) that takes as parameters a list of names of people whose birthday it is today and a dictionary named ages, with names as keys and ages as values, and increments the age of each person in the dictionary whose birthday is today.

  • Write a function check palindrome, which takes a string x as argument and which returns True...

    Write a function check palindrome, which takes a string x as argument and which returns True if x is a palindrome, and False otherwise. A palindrome is a word that reads the same backwards as forwards (like for example “racecar”). Your function should be recursive (i.e. call itself) and proceed as follows. 1. If x is a string of length 0 or 1 return True. 2. If the rst and the last letter of x are di erent, return False....

  • Write a function named mostFrequent that takes two parameters: 1. inFile, a string that is the...

    Write a function named mostFrequent that takes two parameters: 1. inFile, a string that is the name of an input file 2. outFile, a string that is the name of an output file The input file inFile exists when mostFrequent is called; mostFrequent must create outFile. The input file contains only lower case letters and white space. The function mostFrequent identifies the letter(s) that appear most frequently on each line of inFile and writes them to a corresponding line of...

  • Python Question: A palindrome is a string that reads identical forwards and backwards. Examples include abba,...

    Python Question: A palindrome is a string that reads identical forwards and backwards. Examples include abba, abcba, a1b1b1a, houstonnotsuoh etc. Your task is to write a function ispalindrome(string) that reads an input string and returns True if both of the following are true: The string is a palindrome The string has at least one letter (uppercase or lowercase) For example: ispalindrome('racecar') should return True PS: ispalindrome('123321') should return False ispalindrome('racecar') should return True

  • using basic c++ and use no functions from c string library b) Write a fragment of...

    using basic c++ and use no functions from c string library b) Write a fragment of code (with declarations) that reads a pair of words from the keyboard and determines how many letters in corresponding positions of each word are the same. The words consist only of the letters of the English alphabet (uppercase and lowercase). For example, if the words are coat and CATTLE, the following output should be generated: 012245 0122 matching letter in position 0 t is...

  • help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and...

    help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and an int parameter. If both string parameters represent binary numbers and the int parameter is equal to a positive number less than or equal to the length of the longest string parameter, the function should return a binary string whose length is equal to two times the length of the maximum length of the two string parameters whose value is equal to the sum...

  • Write a function in the C++called summary that takes as its parameters an input and output...

    Write a function in the C++called summary that takes as its parameters an input and output file. The function should read two integers find the sum of even numbers, the sum of odd numbers, and the cumulative product between two values lower and upper. The function should return the sum of even, odd, ad cumulative product between the lower and upper values. Please write program in C++.

  • c++ Write a function Count_m_z that takes a string as an input parameter argument and counts...

    c++ Write a function Count_m_z that takes a string as an input parameter argument and counts the number of m, n, o, ... z characters in it. The function returns an integer value for the number of times those 14 lowercase letters appear in the input string. Your function should be named Count_m_z Your function should take one string parameter Your function should return the number of m, n, o, ... z characters as an integer Your function should not...

  • Problem Statement In genetics, most large animals have two copies of every gene, one from each...

    Problem Statement In genetics, most large animals have two copies of every gene, one from each parent. In the simplest genetic model, each of the genes takes on one of two forms, usually represented by an uppercase and lowercase letter of the same value ('A' and 'a', for example). The pair of genes typically contributes to the external qualities of the animal in one of two ways. If both genes are uppercase, they contribute in one way, while if both...

  • Python 1 Write a function called sum_odd that takes two parameters, then calculates and returns the...

    Python 1 Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. 3 To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT