1. Member
Join Date
May 2008
Posts
2
Rep Power
0

## Student--begginer--help!!!

Hey, I have about 5 Programs I worked on my self, did the begging, Middle, as for the End I NEED HELP!! Here they are below.

For the file number functions-- sum 100 dosnt show up

public class NumberFunctions
{

public void alarm (int number)
{
if (number < 1)
System.out.println ("ERROR: Number is less than 1.");
else
for (int count = 1; count <= number; count++)
System.out.println ("Alarm!");
}

public void powersOfTwo()
{
int base = 2;
for (int power = 1; power <= 10; power++)
System.out.println (Math.pow(base,power));
}

public int sum100()
{
int sum = 0;
for (int count = 1; count <= 100; count++)
sum += count;
return sum;
}

public static void main(String[] args) {
NumberFunctions test = new NumberFunctions();
System.out.println("The powers of two are: ");
test.powersOfTwo();
System.out.println("Testing Alarm , calling it with an argument of 9 --");
test.alarm(9);
System.out.println("The sum of 100 is: ");
test.sum100();

}
}

For file NumberFunctions2- i think I did the sumRangeAdvanced wrong the instruction are
Write a method called sumRangeAdvanced that accepts two integer parameters that the range limits. The method should return the sum (inclusive) of the integers in that range regardless of the order of the range limits.

public class NumberFunctions2
{

public int maxOfTwo (int num1, int num2)
{
int result = num1;

if (num2 > num1)
result = num2;

return result;
}

public int sumRange (int start, int end)
{
int sum = 0;

if (end < start)
System.out.println ("ERROR: Invalid Range");
else
for (int num = start; num <= end; num++)
sum += num;

return sum;
}

public int sumRangeAdvanced (int start, int end)
{
int sum = 0;

for (int num = start; num <= end; num++)
sum += num;

return sum;
}

public static void main(String[] args) {
NumberFunctions2 test = new NumberFunctions2();
System.out.println("The max of 2 and 9 is: " + test.maxOfTwo(2,9));
System.out.println("The sum range is: "+ test.sumRange(4,2) );
System.out.println("The sum range with no limits is: "+ test.sumRangeAdvanced(4,10) );

}
}

For File NumberFunctions3- I know my methods are right but im not sure how to make the outcome for the boolen programs. Here are the instructions :
- Write a method called larger that accepts two floating-point parameters (of type double) and returns true if the first parameter is greater than the second, and false otherwise.

-Write a method called countA that accepts a String parameter and returns the number of times the character 'A' is found in the string.

- Write a method called evenlyDivisible that accepts two integer parameters and returns true if the first parameter is evenly divisible by the second, or vice versa, and false otherwise. Return false if either parameter is zero.

public class NumberFunctions3
{

public boolean larger (double num1, double num2)
{
return (num1 > num2);
}

public int countA (String text)
{
int count = 0;
for (int position = 0; position < text.length(); position++)
if (text.charAt(position) == 'A')
count++;
return count;
}

public boolean evenlyDivisible (int num1, int num2)
{
boolean result = false;

if (num1 != 0 && num2 != 0)
if (num1 % num2 == 0 || num2 % num1 == 0)
result = true;

return result;
}

public static void main(String[] args) {
NumberFunctions3 test = new NumberFunctions3();
System.out.println("The larger of 7 and 12 is: " + test.larger(7,12));
System.out.println("There are: " + test.CountA() + " In this Program");
System.out.println("It is evenly divisible: "+ test.evenlyDivisible() );

}
}

For File NumberFunctions4- I Dont know what I did wrong. Here are the instructions:
Write a method called average that accepts two integer parameters and returns their average as a floating point value.

Overload the average method of Exercise 10 such that if three integers are provided as parameters, the method returns the average of all three.

Overload the average method of Exercise 10 to accept four integer parameters and return their average.

public class NumberFunctions4
{

public double average (int num1, int num2)
{
return (num1 + num2) / 2.0;
}

public double average2 (int num1, int num2, int num3)
{
return (num1 + num2 + num3) / 3.0;
}

public double average3 (int num1, int num2, int num3, int num4)
{
return (num1 + num2 + num3 + num4) / 4.0;
}

public static void main(String[] args) {
NumberFunctions2 test = new NumberFunctions4();
System.out.println("The Average of 6 and 8: " + test.average(6,8));
System.out.println("The Average of 6 , 8, and 12 is: "+ test.average2(6,8,12) );
System.out.println("The Average of 6, 8,12,and 16 is: "+ test.average3(6,8,12,16) );

}
}

For File NumberFunctions5- Same thing, im' not so sure what i did wrong but here were the directions:
Write a method called multiConcat that takes a String and an integer as parameters. Return a String that consists of the string parameter concatenated with itself count times, where count is the integer parameter. For example, if the parameter values are 'hi' and 4, the return value is 'hihihihi'. Return the original string if the integer parameter is less than 2.

Overload the multiConcat method from Exercise 13 such that if the integer parameter is not provided, the method returns the string concatenated with itself. For example, if the parameter is 'test', the return value is 'testtest'

Write a method called reverse that accepts a String parameter and returns a string that contains the characters of the parameter in reverse order. Note that there is a method in the String class that performs this operation, but for the sake of learning, you are expected to write your own.

public class NumberFunctions5
{

public String reverse (String text)
{
String result = "";

for (int place = text.length()-1; place >= 0; place--)
result += text.charAt(place);

return result;
}

public String multiConcat (String text, int repeats)
{
String result = text;

if (repeats > 1)
for (int count = 2; count <= repeats; count++)
result += text;

return result;
}
public String multiConcat2 (String text)
{
String result = text + text;
return result;
}

public static void main(String[] args) {
NumberFunctions2 test = new NumberFunctions5();
System.out.println("Reversed is: " + test.reverse(test));
System.out.println("here is hi four times: "+ test.multiConcat(hi,4) );
System.out.println("Here is test 2ce "+ test.multiConcat2(test,2) );

}
}

I'M VERY GREATFUL FOR WHOEVER HELP!! THANKS!!

2. For the first part, do it as follows.

Java Code:
`System.out.println("The sum of 100 is: " + test.sum100());`

3. For the second part, change this

Java Code:
`NumberFunctions2 test = new NumberFunctions4();`
in to this,

Java Code:
`NumberFunctions4 test = new NumberFunctions4();`

4. Member
Join Date
May 2008
Posts
2
Rep Power
0
Just started about 8 weeks ago, Thanks for the help

5. Ok, if you solved the problem please mark the thread solved. If you have any question related to this, no need to do it. :)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•