# Please need a help with my homework (math methods)

• May 1st, 2013, 09:53 AM
Dr.UaE
Please need a help with my homework (math methods)
Hello, I really need some help on some Java programming homework that is due tonight&tomorrow. Here is the homework (3 problems):

1) (Displaying a Square of Asterisks) Write a method squareOfAsterisks that displays a solid square (the same number of rows and columns) of asterisks whose side is specified in integer parameter
side. For example, if side is 4, the method should display

****
****
****

=========
2) (Circle Area) Write an application that prompts the user for the radius of a circle and uses a method called circleArea to calculate the area of the circle.

=========
3) (Hypotenuse Calculations) Define a method hypotenuse that calculates the hypotenuse of
a right triangle when the lengths of the other two sides are given. The method should take two arguments of type double and return the hypotenuse as a double. Incorporate this method into an application that reads values for side1 and side2 and performs the calculation with the hypotenuse method. Use Math methods pow and sqrt to determine the length of the hypotenuse for each of the
triangles in Fig. 6.15. [Note: Class Math also provides method hypot to perform this calculation.]

Attachment 2061

• May 1st, 2013, 09:54 AM
Dr.UaE
Re: Please need a help with my homework (math methods)
Yes, also we have to use the main to call the methods.
• May 1st, 2013, 10:00 AM
Norm
Re: Please need a help with my homework (math methods)
• May 1st, 2013, 01:13 PM
Dr.UaE
Re: Please need a help with my homework (math methods)
I'm having a problem creating the whole code, I don't know how to use math methods to solve these problems..
• May 1st, 2013, 01:23 PM
Norm
Re: Please need a help with my homework (math methods)
What kind of math do you need to do? Which of the Math class's methods are you having problems with?
Can you make a small, complete program that shows the problem you are having?
• May 1st, 2013, 01:50 PM
Dr.UaE
Re: Please need a help with my homework (math methods)
For the first problem, I have tried this code but still wrong!

Code :

```public class SquareAst   {   public static void main (String [args]){   sq();   public static void Sq ( int n1 )       {   for (int n = 1; n <= n1; n++)   {   for (int m = 1; m <= n1; m++)   {   System.out.print("*");   }   System.out.println();   }   }     } }```
• May 1st, 2013, 01:54 PM
pawan4angel
Re: Please need a help with my homework (math methods)
1. take number from user using scanner class, and run loop inner and outer loop to print square *
3. take perpendicular and base from user using scanner class, now apply the theorem " h*h = p*p + b*b ", you will get all the answer by making function...
• May 1st, 2013, 02:02 PM
Dr.UaE
Re: Please need a help with my homework (math methods)
can you show me in simple codes please,

• May 1st, 2013, 02:26 PM
Norm
Re: Please need a help with my homework (math methods)
Can you post the program's output and explain what is wrong with it?
• May 1st, 2013, 02:33 PM
Dr.UaE
Re: Please need a help with my homework (math methods)
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
void is an invalid type for the variable Sq
Syntax error on token "(", ; expected
Syntax error on token ")", ; expected

at SquareAst.main(SquareAst.java:9)
• May 1st, 2013, 02:47 PM
Norm
Re: Please need a help with my homework (math methods)
Please copy the full text of the compiler's error messages. They contain important information about the problems. The abbreviated messages you posted leaves off info about the problem.

The message should show the source with a ^ under the location of the error.
Here is a sample from the javac compiler:
Code :

```TestSorts.java:138: cannot find symbol symbol : variable var location: class TestSorts var = 2; ^```

Take a look at the tutorial for how to define a simple class and its main() method: http://docs.oracle.com/javase/tutori...ava/win32.html
• May 1st, 2013, 03:01 PM
pawan4angel
Re: Please need a help with my homework (math methods)
1. How to print * Square

class Square
{
psvm(String args[])
{
// take input from user in max variable; like max=5

for (i=0;i<max;i++)
{
for (j=0;j<max;j++)
{
//print statement
}
//print statement for next line
}

}
//I hope this is helpful to you.........

--- Update ---

2. How to calculate circle area

class Circle
{
psvm(String args[])
{
// take input from user in radius variable; like max=10

///print area

}
--- Update ---

[/COLOR]3. How to calculate H-side

class Triangle
{
psvm(String args[])
{
// take input from user in perp and base variable; like perp=12 and base =5

int h_side=SQRT(perp*perp+base*base);
///print H-side

}
• May 1st, 2013, 03:06 PM
Dr.UaE
Re: Please need a help with my homework (math methods)
Code :

```public class Square {     public static void main(String[] args) {     int max=5;     for (int i=0;i<max;i++) {   for (int j=0;j<max;j++)   {   System.out.println("*"); } System.out.println("");   }   }   }```

Did I miss something?
• May 1st, 2013, 10:58 PM
jps
Re: Please need a help with my homework (math methods)
Quote:

Originally Posted by Dr.UaE
Did I miss something?

What happens when you run it? Is the output correct?
• May 2nd, 2013, 12:41 AM
pawan4angel
Re: Please need a help with my homework (math methods)
Quote:

Originally Posted by jps
What happens when you run it? Is the output correct?

just type "System.out.print("*");" in_place_of "System.out.println("*");", and your program will run fine........