Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 15 of 15

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

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    bAs1r.png

    thanks in advance!


  2. #2
    Junior Member
    Join Date
    May 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

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

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    May 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    May 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    For the first problem, I have tried this code but still wrong!

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

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Location
    Earth
    Posts
    21
    Thanks
    0
    Thanked 1 Time in 1 Post

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

  8. #8
    Junior Member
    Join Date
    May 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    can you show me in simple codes please,

    thank you for your post

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    Can you post the program's output and explain what is wrong with it?
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    May 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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:
    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
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Apr 2013
    Location
    Earth
    Posts
    21
    Thanks
    0
    Thanked 1 Time in 1 Post

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

    }

  13. #13
    Junior Member
    Join Date
    May 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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?

  14. #14
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

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

    Quote Originally Posted by Dr.UaE View Post
    Did I miss something?
    What happens when you run it? Is the output correct?

  15. #15
    Junior Member
    Join Date
    Apr 2013
    Location
    Earth
    Posts
    21
    Thanks
    0
    Thanked 1 Time in 1 Post

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

    Quote Originally Posted by jps View Post
    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........

Similar Threads

  1. [SOLVED] Is it the Math or is it my Methods?
    By Praetorian in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 11th, 2013, 07:25 PM
  2. Homework Help - Conductors & Methods
    By RM1091 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 16th, 2012, 01:20 PM
  3. Why and where abstract methods & classes and static methods are used?
    By ajaysharma in forum Object Oriented Programming
    Replies: 7
    Last Post: July 14th, 2012, 01:16 AM
  4. [SOLVED] Help with Math.tan and Math.atan
    By Dr.Code in forum Algorithms & Recursion
    Replies: 6
    Last Post: July 2nd, 2012, 05:54 AM
  5. Confusion with Math.toDegrees() and Math.toRadians(). Please help.
    By marksquall in forum Java Theory & Questions
    Replies: 3
    Last Post: June 23rd, 2011, 01:28 AM