Results 1 to 2 of 2
  1. #1
    Lach is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Help with JOptionPane and triangles.

    Hello!. I have to create a program that asks for a user to input 3 coordinates for a triangle, and then some calculations will be made such as perimeter and area, etc. So right now i have this:

    Java Code:
    import java.util.Scanner;
    import javax.swing.JOptionPane;
    
    public class Triangle
    { 
       
    public static void main(String[] args)
    {
       double side1 = 0;
       double side2 = 0;
       double side3 = 0;
       
       //Coordinate 1
       String side1x = JOptionPane.showInputDialog(null, "Enter x1 for point A: ", "User Input", JOptionPane.QUESTION_MESSAGE);
       
       int x1 = Integer.parseInt(side1x);
       
       String side1y = JOptionPane.showInputDialog(null, "Enter y1 for point A: ", "User Input", JOptionPane.QUESTION_MESSAGE);
       
       int x2 = Integer.parseInt(side1y);
       
       //Coordinate 2
       String side2x = JOptionPane.showInputDialog(null, "Enter x2 for point B: ", "User Input", JOptionPane.QUESTION_MESSAGE);
       
       int y1 = Integer.parseInt(side2x);
       
       String side2y = JOptionPane.showInputDialog(null, "Enter y2 for point B: ", "User Input", JOptionPane.QUESTION_MESSAGE);
       
       int y2 = Integer.parseInt(side2y);
       
       //Coordinate 3
       String side3x = JOptionPane.showInputDialog(null, "Enter x3 for point C: ", "User Input", JOptionPane.QUESTION_MESSAGE);
    As of right now all this does is ask for user input of x1 ,x2, y1, y2, etc., and keeps them in separate variables. What i am wondering how to do is make it so that x1 and x2 could be combined together to create a coordinate of a point of the triangle. Can anyone help me on this one? Thanks in advance!

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Help with JOptionPane and triangles.

    For starters you do not want to combine x1 and x2. You want x1 and y1, x2 and y2, x3 and y3. Have a look at the Point class.

Similar Threads

  1. Making Triangles
    By truegamer95 in forum New To Java
    Replies: 2
    Last Post: 02-08-2013, 04:41 PM
  2. Two triangles of stars next to each other
    By Aero in forum New To Java
    Replies: 3
    Last Post: 09-26-2011, 07:20 PM
  3. Drawing out triangles
    By leiferouis in forum New To Java
    Replies: 24
    Last Post: 01-16-2009, 08:18 PM
  4. Triangles
    By CodeDog in forum New To Java
    Replies: 9
    Last Post: 10-14-2008, 09:18 PM
  5. asterisks triangles
    By Dan121 in forum New To Java
    Replies: 1
    Last Post: 01-12-2008, 07:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •