1 Attachment(s)

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

thanks in advance!

Re: Please need a help with my homework (math methods)

Yes, also we have to use the main to call the methods.

Re: Please need a help with my homework (math methods)

Do you have any specific questions about your assignment?

Please post your code and any questions about problems you are having.

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..

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?

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();
}
}
}
}

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 *

2. take radius from user using scanner class, calculate area=pie*radius

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...

Re: Please need a help with my homework (math methods)

can you show me in simple codes please,

thank you for your post

Re: Please need a help with my homework (math methods)

Can you post the program's output and explain what is wrong with it?

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)

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

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

}

}// your program ends here......

}

//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

int area=pie*radius*radius;

///print area

}// your program ends here......

}

--- 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

}// your program ends here......

}

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?

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?

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........