wiki:k2014/demot/demo7english
Last modified 3 years ago Last modified on 2015-02-13 11:11:32

Demot » Demo 7, 2.3.2015

Return using NETTIDEMOWWW-program.

Remember to test your tasks with ComTest or JUnit.

Task 1. Java and String-class

What methods from String class would be suitable for solving the following problems and how could they be used:

  1. Does string contain other letters than the ones given as parameter k?
    line="kissa" k="aik" -> returns true, k="aiks" -> returns false
    
  2. Where is the last '\' of a line?
    "C:\mytemp\ohj2\vesal\Koe.java"  -> 
    returns the index of the last '\'-character.
    
  3. Does the string contain any letter from the group k?
    line="kissa" k="ibm" -> yes, it contains , k="pc"  -> no, it doesn't contain
    

Task 2. String-class more questions

Keep researching the String-class for answers to these questions. Return the example codes, one line might not be enough to solve these:

  1. is " matti* " the same as "Matti Nykänen"?
    (answer: yes.  Notice wildchar *, empty spaces, capital and non-capital letters)
    
  2. How many characters there are in the line "Kissa istuu puussa"?
    characters from "a-j" or "r-w"  ("a-j" == "abcdefghij")
    (answer: 2*a + 2*i +5*s + 1*t + 4*u = 14)
    

Task 3. Weight of letter

Look in luvussa 9.5.2 for example function "postimaksu". Try to mimic this function or just plan out your own biggestWeightOfLetter that will return the largest weight that can be sent with the given amount of money. The answer can be done with multiple If-statements.

Task 4*. Weight of letter with an array

biggestWeightOfLetter, do the method from task 3 with an array. Try to make changing prices in the array as easy as possible.

Tehtävä 5. Palindrome

Write function palindrome that returns true or false depending if the given word is a palindrome or not. For example abba is a palindrome, help is not. There are no spaces or special markers in the given word.

Task 8*. Limits of an array

Make methods best(returns the biggest number in a double array), worst(returns the smallest number in a double array) and sum (returns the sum of values in a double array). Using these methods write method sumWithoutTheBestAndTheWorst that returns the sum of all the values in a double array except for the smallest and largest value stored in it.