Question

1.Method name: findSmallestPositiveNumber Parameter(s): A String containing integer numbers separated by spaces. There must be at...

1.Method name: findSmallestPositiveNumber

Parameter(s): A String containing integer numbers separated by spaces. There must be at least one positive number in the String.
Return value: An int value that is the smallest number greater than 0 in the input string.
Example: findSmallestPositiveNumber("2 -4 5") should return 2.
Note: Even though I put this first, I would consider working on this later. The other methods are basically just applying the patterns we looked at in class. This one is similar but requires a little more working out the logic of the problem.


2.Method name: lowestAlphabetically
Parameter(s): A String of lower-case words separated by spaces and made up of the letters a-z. The String will have at least one word.
Return value: A String containing the lowest alphabetical word. The String method compareTo() does a lexicographic comparison between two strings, which allows you to test for the lowest alphabetical word. Read documentation on compareTo() in order to understand how to use it.
Example: lowestAlphabetically("cat dog apple fish") would return "apple".


3.Method name: findSmallestNumberInTwoStrings
Parameter(s): Two String parameters. Each string is made up of numbers separated by spaces. The first string must have at least one number.
Return value: An int containing the smallest number found in the two strings.
Example: findSmallestNumberInTwoStrings("12 3 5", "2 -1 10") would return -1.


4.Method name: curveScores
Parameter(s): A String containing numbers from 0 to 100. Each number is separated by a space. There must be at least one number in the String.
Return value: A String of numbers scaled so that the highest number in the parameter String becomes 100 and all the other numbers are moved up by the same amount. This String should also be numbers separated by spaces with no additional characters.
Example: curveScores("45 85 90") would return "55 95 100".


5.Method name: containsThisColor
Parameter(s): A Picture object that is at least 1x1 pixels and a Color object.
Return value: A boolean value. Return true if the Color parameter matches one of the pixels in the image and false otherwise. A color match is done by using the .equals method rather than ==.
Example: For a 1 pixel picture with a color of (100, 200, 50) and a color to search for of (100, 100, 100), this method would return false.

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

Thanks for posting the question, here are the methods for the first 4 sub questions

_________________________________________________________________________________________________

public static int findSmallestPositiveNumber(String numString){

    String[] tokens = numString.split("\\s+");

    int smallestPositiveNumber=Integer.MAX_VALUE;
    for(String token:tokens){
        int number = Integer.parseInt(token);
        if(smallestPositiveNumber > number && number>0) {
            smallestPositiveNumber = number;
        }
    }
    return smallestPositiveNumber;
}

public static String lowestAlphabetically(String words){

    String tokens[] = words.split("\\s+");
    String smallestWord = tokens[0];
    for(String token:tokens) {
        if (smallestWord.compareTo(token)<0){
            smallestWord=token;
        }
    }
    return smallestWord;
}

public static int findSmallestNumberInTwoStrings(String one, String two){

    int smallestNum=Integer.MAX_VALUE;

    String[] oneTokens = one.split("\\s+");
    for(String token:oneTokens){
        if(Integer.parseInt(token)<smallestNum){
            smallestNum=Integer.parseInt(token);
        }
    }
    String[] twoTokens = two.split("\\s+");
    for(String token:twoTokens){
        if(Integer.parseInt(token)<smallestNum){
            smallestNum=Integer.parseInt(token);
        }
    }
    return smallestNum;

}

public static String curveScores(String numbers){

    String[] number = numbers.split("\\s+");
    int maxNumber = Integer.MIN_VALUE;
    for(String token :number){
        if(maxNumber<Integer.parseInt(token)){
            maxNumber=Integer.parseInt(token);
        }
    }
    int difference = 100-maxNumber;
    StringBuilder builder = new StringBuilder();
    for(String num:number){
        builder.append(Integer.parseInt(num)+difference).append(" ");
    }
    return builder.toString().trim();

}

___________________________________________________________________________________________________

Add a comment
Know the answer?
Add Answer to:
1.Method name: findSmallestPositiveNumber Parameter(s): A String containing integer numbers separated by spaces. There must be at...
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
  • The goal of this assignment is to use loop patterns to solve a variety of problems...

    The goal of this assignment is to use loop patterns to solve a variety of problems Starting 1. In Eclipse, create a new project or use an assignments one. Add a package a4, and a class SearchAndOptimizingLoops to that package. Copy and paste Picture.java and an image file from prior work into this package (Picture.java should update itself to the a4 package) 2. In your class, implement the static methods specified below 3. All methods you write should have a...

  • Please I need help. Java language Method name: getScores Return value is a String of numbers...

    Please I need help. Java language Method name: getScores Return value is a String of numbers scaled so that the highest number in the parameter String becomes 100 and all the other numbers are moved up by the same amount. This String should also be numbers separated by spaces with no additional characters. The order of the numbers should stay the same, so that a number in the original string has the equivalent scaled number in the returned string in...

  • Please I need help. Java language Method name: getScores Return value is a String of numbers...

    Please I need help. Java language Method name: getScores Return value is a String of numbers scaled so that the highest number in the parameter String becomes 100 and all the other numbers are moved up by the same amount. This String should also be numbers separated by spaces with no additional characters. The order of the numbers should stay the same, so that a number in the original string has the equivalent scaled number in the returned string in...

  • public static boolean isArithmetic(java.lang.String text) Given a string of text containing numbers separated by commas, returns...

    public static boolean isArithmetic(java.lang.String text) Given a string of text containing numbers separated by commas, returns true if the numbers form an arithmetic sequence (a sequence in which each value differs from the previous one by a fixed amount). For example, given "2,4,6,8", the method returns true given "-2,5,12,19,26", returns true given "2,4,7", returns false given "1,2,23skidoo", returns false The method should return true for any string containing two or fewer numbers and false for any invalid string. Assume that...

  • use Java and it must work for any name String Manipulator Write a program to manipulate...

    use Java and it must work for any name String Manipulator Write a program to manipulate Strings. Store your full name into one String variable. It must include first name, middle name, last name, cach separated by spaces. Spaces could vary. If you do not have a middle name make up one For example the string to be processed could be any of the following John Plain Doe John Plain Doc John Plain Doe Your program must be able to...

  • Write a static method called printWithSpaces that takes a String as its parameter and prints the...

    Write a static method called printWithSpaces that takes a String as its parameter and prints the characters of the string separated by spaces. For example: > Methods.printWithSpaces("method") m e t h o d You should have a single space after the last character. This method should not return a value. That is similar to this code for printing the string vertically public static void printVertical(String s) { for (int i = 0; i < s.length(); i++) { char c =...

  • Write a method called printReverse() that takes a string and uses recursion to print the contents...

    Write a method called printReverse() that takes a string and uses recursion to print the contents of the string in reverse order. The string itself should not be reversed; it must be left in its original form. The method has the following header:   void printReverse(String s, int i) where s is a reference to the string, and i is an integer parameter that you may use as you see fit. You do not need to code up this method as...

  • Write a program that takes a String containing a text using the method signature String useProperGrammar(String...

    Write a program that takes a String containing a text using the method signature String useProperGrammar(String text) Your method should replace the word ‘2’ with ‘to’ and return the updated text. For example, useProperGrammar("can you go 2 the store?") should return "can you go to the store?" This method should also print out the number of grammatical errors that were fixed. For example, for useProperGrammar("back 2 back 2 back"), the method would also print: Fixed 2 grammatical errors: In the...

  • Write a python function score_formatter() that takes one parameter, which is a formatted string that contains...

    Write a python function score_formatter() that takes one parameter, which is a formatted string that contains information about the score received by a student in a particular subject. The function analyzes the string and returns a reformatted string for the score. You will need to use the function re.sub that is discussed in the lecture notes. If the string does not match the pattern, the function returns the string "error". The input string is always given in the format specified...

  • String Processing Labs Directions: Write a main program to test the three functions described below, Input...

    String Processing Labs Directions: Write a main program to test the three functions described below, Input is from a file, and output is to a file. 1. The function Another parameter is a char variable with a letter value. The function outputs the number of times the char value appears in the string. processes a string containing letters of the alphabet, which is a parameter 2. This Boolean function has two string parameters. It returns true when the first str...

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