Question

In this assignment, you will be creating three static methods as described below: The method duplicate...

In this assignment, you will be creating three static methods as described below:

  1. The method duplicate should accept one parameter of type String (named “str”). The method should return a String with every character in str repeated n times, where n is the length of str if str has an odd number of characters

    e.g. duplicate("Hat") should return "HHHaaattt"

    and n is double the length of str if str has an even number of characters

    E.g. duplicate("Hi") should return "HHHHiiii".


  2. isEdhesivePalindrome - The method isEdhesivePalindrome should accept a parameter of type String (named “str”) and return true if str is an "Edhesive Palindrome,” and false otherwise.

    An Edhesive Palindrome must meet the following requirements:

    1. The String parameter str must read the same backward as forwards. (e.g. "racecar" is a valid Edhesive Palindrome). Case does NOT matter. (e.g. "RaceCar" is still valid)
    2. The following characters are equivalent:
      • a ~ 4
      • e ~ 3
      • o ~ 0

      NOTE: The letters are shown in lower-case, but since the case does NOT matter, both 'a' and 'A' is equivalent to '4'. (e.g. "R4ceCar" is still valid)

    3. The String parameter str must be of length greater than 3 and less than 15 (e.g. "R4ceCar" is still valid. But "mom" and "dad" are NOT valid).

    If anyone of these 3 requirements is NOT satisfied, then the String parameter str is NOT considered an Edhesive Palindrome, and the method should return false. If all 3 requirements are satisfied, then the method returns true.

    E.g. using the examples above, isEdhesivePalindrome(“R4ceCar”) should return true, whereas isEdhesivePalindrome(“dad”) and isEdhesivePalindrome(“hello”) should both return false.

  3. numberScramble - The method numberScramble should accept one parameter of type double (named “num”) and return a value of type double. If the input parameter is less than 0, return 0.0. Otherwise, the following mathematical operations should be performed on the parameter before returning:
    1. add 5 to num
    2. divide num by 2
    3. square root num

    E.g. numberScramble(3.0) should return 2.0

    Breakdown:

    1. 3.0 + 5 = 8.0
    2. 8.0 / 2 = 4.0
    3. Square root of 4.0 = 2.0

To test your three methods, ask the user for inputs sequentially in your main method and then print out the results of the appropriate method. The output of your main method should match the sample runs below, so you should refer to these examples for the appropriate output.

Sample Run 1

Welcome to the Methods Sampler Platter. Please enter a String to duplicate.
Opera
The duplicated String is: OOOOOpppppeeeeerrrrraaaaa
Next, please enter a String to check for Edhesive Palindromes.
Avid div4
Nice, you found an Edhesive Palindrome!
Almost done! Please enter a number to scramble.
67
The scrambled number is: 6.0

Sample Run 2

Welcome to the Methods Sampler Platter. Please enter a String to duplicate.
Aria
The duplicated String is: AAAAAAAArrrrrrrriiiiiiiiaaaaaaaa
Next, please enter a String to check for Edhesive Palindromes.
palindrome
Too bad, that isn't an Edhesive Palindrome.
Almost done! Please enter a number to scramble.
13
The scrambled number is: 3.0
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

// Methods.java

import java.util.Scanner;

public class Methods {

   public static void main(String[] args) {
String dupStr,palStr;
double scrval;
   /*
   * Creating an Scanner class object which is used to get the inputs
   * entered by the user
   */
   Scanner sc = new Scanner(System.in);

        //Getting the input entered by the user
System.out.println("Welcome to the Methods Sampler Platter. Please enter a String to duplicate.");
dupStr=sc.nextLine();

System.out.println("The duplicated String is: "+duplicate(dupStr));
System.out.println("Next, please enter a String to check for Edhesive Palindromes.");
       palStr=sc.nextLine();
           if(isEdhesivePalindrome(palStr))
           {
               System.out.println("Nice, you found an Edhesive Palindrome!");
           }
           else
           {
               System.out.println("Too bad, that isn't an Edhesive Palindrome.");
           }
      
           System.out.println("Almost done! Please enter a number to scramble.");
       scrval=sc.nextDouble();
       System.out.println("The scrambled number is: "+numberScramble(scrval));
      
  
   }

   private static double numberScramble(double d) {
       d+=5;
       d/=2;
       return Math.sqrt(d);
   }

   private static boolean isEdhesivePalindrome(String s) {
       String newStr="";
       if(s.length()<=3 || s.length()>=15)
           return false;
       else
       {
           s=s.toLowerCase();
           for(int i=0;i<s.length();i++)
           {
               if(s.charAt(i)=='4')
               {
                   newStr+='a';
               }
               else if(s.charAt(i)=='3')
               {
                   newStr+='e';
               }
               else if(s.charAt(i)=='0')
               {
                   newStr+='o';
               }
               else if(s.charAt(i)!=' ')
               {
                   newStr+=s.charAt(i);
               }
              
           }
          
           for(int i=0;i<newStr.length()/2;i++)
           {
               if(newStr.charAt(i)!=newStr.charAt((newStr.length()-1)-i))
                   return false;
           }  
       }
      
      
       return true;
   }

   private static String duplicate(String s) {
       String newStr="";
       if(s.length()%2==0)
       {
           for(int i=0;i<s.length();i++)
           {
               for(int j=0;j<s.length()*2;j++)
               {
                   newStr+=s.charAt(i);
               }
           }
       }
       else if(s.length()%2!=0)
       {
           for(int i=0;i<s.length();i++)
           {
               for(int j=0;j<s.length();j++)
               {
                   newStr+=s.charAt(i);
               }
           }
       }
       return newStr;
   }

}


========================================

Output#1:

Welcome to the Methods Sampler Platter. Please enter a String to duplicate.
Opera
The duplicated String is: OOOOOpppppeeeeerrrrraaaaa
Next, please enter a String to check for Edhesive Palindromes.
Avid div4
Nice, you found an Edhesive Palindrome!
Almost done! Please enter a number to scramble.
67
The scrambled number is: 6.0

================================

Output#2:

Welcome to the Methods Sampler Platter. Please enter a String to duplicate.
Aria
The duplicated String is: AAAAAAAArrrrrrrriiiiiiiiaaaaaaaa
Next, please enter a String to check for Edhesive Palindromes.
palindrome
Too bad, that isn't an Edhesive Palindrome.
Almost done! Please enter a number to scramble.
13
The scrambled number is: 3.0


=====================Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
In this assignment, you will be creating three static methods as described below: The method duplicate...
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
  • Can you help me make these two methods listed below work? I have code written but...

    Can you help me make these two methods listed below work? I have code written but it is not working. I would appreciate any advice or help. Function "isAPalidrome" accepts an array of characters and returns an integer. You must use pointer operations only, no arrays. This function should return 1 (true) if the parameter 'string' is a palindrome, or 0 (false) if 'string' is not a palindrome. A palindrome is a sequence of characters which when reversed, is the...

  • JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using...

    JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using recursion. The method signatures are included in the starter code below, with a more detailed explanation of what function the method should perform. You will be writing the following methods: stringClean() palindromeChecker() reverseString() totalWord() permutation() You will be using tools in the String class like .substring(), .charAt(), and .length() in all of these methods, so be careful with indices. If you get stuck, think...

  • Hint: User will enter certain number of random words, you need to read the input as...

    Hint: User will enter certain number of random words, you need to read the input as string and evaluate based on the following instructions. Write a void method called palindromeCheck that takes NO argument. The method should have functionality to check whether or not the word is a palindrome and print to the screen all of the palindromes, one per line. Also, the last line of the output should have the message: “There are x palindromes out of y words...

  • Your program must prompt the user to enter a string. The program must then test the...

    Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....

  • Game Development: Uno For this assignment you will be creating the game of Uno (See the...

    Game Development: Uno For this assignment you will be creating the game of Uno (See the accompanying pdf for the instructions of the game). Your version will adhere to all the rules except that only the next player can issue a challenge against the previous player in regards to penalties, and your games must have at least three (3) players and at most nine (9) players. To begin, you must create the class Card which contains: Private string field named...

  • Methods: Net beans IDE Java two methods. Identifier: calculateScore(String word) Parameters: word – the word for...

    Methods: Net beans IDE Java two methods. Identifier: calculateScore(String word) Parameters: word – the word for which you should calculate the points in Scrabble Return Value: int – the number of points for the parameter word Other: This method should be static. This method should use the following system for scoring: 0 – blank 1 – e, a, i, o, n, r, t, l, s, u 2 – d, g 3 – b, c, m, p 4 – f, h,...

  • Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so...

    Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so they throw exceptions when the following errors occur. - The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999. - The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift. - The ProductionWorker class should thrown anexception named InvalidPayRate when it receives a negative number...

  • 3. Write Java methods to accomplish each of the following Write a method named simpleAry which...

    3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...

  • This assignment is designed to give you practice with Javadoc, creating unit tests and using Junit....

    This assignment is designed to give you practice with Javadoc, creating unit tests and using Junit. Be sure to follow all style and documentation requirements for THIS class. See the style and documentation requirements posted on Canvas. You are to name your package assign1 and your file Palindrome.java. Palindrome Class Palindrome testString : String + Palindrome (String) + isPalindrome (): boolean The method isPalindrome is to determine if a string is a palindrome. A palindrome, for this assignment, is defined...

  • Question 2 (80 marks) This programming assignment is divided into two parts: (a) You will develop...

    Question 2 (80 marks) This programming assignment is divided into two parts: (a) You will develop a Java class called StringSummary based on the UML class diagram depicted in Figure 1 A user will enter a string of sentence (Figure 2), and your program will provide a summary of the sentence as shown in sample output Figure 3. The class contains several private attributes: • str stores the sentence input by user. • specialChars stores number of special characters (i.e....

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
ADVERTISEMENT