|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

05-08-2008, 05:51 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 2
|
|
|
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!!
|
|

05-08-2008, 06:26 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
|
|
For the first part, do it as follows.
System.out.println("The sum of 100 is: " + test.sum100());
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-08-2008, 06:31 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
|
|
For the second part, change this
NumberFunctions2 test = new NumberFunctions4();
in to this,
NumberFunctions4 test = new NumberFunctions4();
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-08-2008, 06:32 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
|
|
|
You have done the same thing for part three also. Check it and correct.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-08-2008, 06:32 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
|
|
You have to learn a lot pal. How long you start work on Java? 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-08-2008, 04:38 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 2
|
|
|
Just started about 8 weeks ago, Thanks for the help
|
|

05-09-2008, 05:37 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
|
|
Ok, if you solved the problem please mark the thread solved. If you have any question related to this, no need to do it. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|