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

Thread: help java prog

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help java prog

    how will i do this??

    private double height;//Height
     private double base;//Base length
     public Triangle(double h, double b);//Constructor
     public void setHeight(double x);//Sets height
     public double getHeight();//Gets height
     public void setBase(double x);//Sets base length
     public double getBase();//Gets base length
     public double getArea();//Returns the area of the triangle
    Use the Scanner class in the main method. The main method will be a calling method where it invokes all method in the Triangle class.
    ...
    /**
     * @(#)gg.java
     *
     *
     * @author 
     * @version 1.00 2012/10/22
     */
     
    import java.util.*;
    public class gg {
    	Scanner br= new Scanner(System.in);
    	private double height;
    	private double base;
        public static void main(String []args) {
        double h=getHeight();
        double b=getBase();	
        	System.out.println(""+b.getArea());
        }
        public double getHeight(){
        	System.out.println("Enter height of the triangle: ");
        	height=br.nextDouble();
        	return height;
        }
            public double getBase(){
        	System.out.println("Enter Base of the triangle: ");
        	base=br.nextDouble();
        	return base;
        }
        public double getArea(){
    	return (0.5*height*base);
        }
     
     
    }

    Sample Output:
    Enter height of the triangle : 5
    Enter base of the triangle : 10
    The area of a triangle is 25.00


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: help java prog

    What exactly is your question? Where are you stuck?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help java prog

    i do not know what will i do the the constructor and how will i add the other to my program

  4. #4
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help java prog

    bump!!!!!!!!!!

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: help java prog

    Again, where are you stuck with those things? What exactly are you confused by with the constructor? What exactly do you mean by "the other"?

    Please don't bump your thread. It just makes you look impatient and like your thread is receiving more replies, which will make people think you're getting more help so they don't need to check out your post.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help java prog

    help me add those methods to my program??
    how will i add public void setBase(double x) and public void setHeight(double x) also the public Triangle(double h, double b); to my program??

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: help java prog

    That isn't really how this works. We can't do your homework for you. What is giving you trouble with adding those methods? What have you tried?

    I'd recommend a google search of "java methods" for a link to the basic tutorials on writing methods.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help java prog

    according to my post above.. where should i plase the formula 0.5*height*base is it to the Triangle class or the area?

Similar Threads

  1. help java prog
    By darking123 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 18th, 2012, 10:38 PM
  2. Help with prog please.
    By Flantoons in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 15th, 2011, 05:10 AM
  3. Socket related prog
    By amitabh in forum Java Networking
    Replies: 1
    Last Post: March 18th, 2011, 08:47 AM
  4. how to write servlet nd jsp prog. in netbeans
    By javaking in forum Java IDEs
    Replies: 1
    Last Post: December 20th, 2010, 09:12 PM
  5. need help prog skipping method
    By Pulse_Irl in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 11th, 2010, 07:57 AM