https://www.liquidpoker.net/


LP international    Contact            Users: 309 Active, 2 Logged in - Time: 02:42

Java Programming Question

New to LiquidPoker? Register here for free!
Forum Index > Poker Blogs
StArCuE   United States. Feb 20 2011 19:46. Posts 123
Okay this is a Comp Sci 1 class and we work mostly with Java. One of the assignments which I am posting below calculated the perimeter and area of a triangle. But now I need to use a dialog box for input and a dialog box for output. So yah I need to use javax.swing.JOptionPane and a string tokenizer. The output needs to be in decimal format as well with one dialog box for the sides of the triangle, perimter, and area. If anyone can guide me through this I would appreciate it. Thanks Chris.

// Interactive Triangle Program
// This program asks the user to input three real numbers
// which are the lengths of the sides of a triangle, and
// calculates the perimeter and area of the triangle and
// prints the results
// Christopher
// Java 1.5, Windows XP

import java.util. * ;

public class InteractiveTriangle
{
static Scanner console = new Scanner (System.in) ;

public static void main (String [] args) throws Exception
{ double num1, num2, num3 ; // input values for sides of the triangle
double sum, s, area;
// Explain the program to the user
System.out.println ("This program finds the sum of the sides of a triangle" ;

// Input the three numbers
System.out.println ("Input your first side." ;
num1 = console.nextDouble () ;

System.out.println ("Input your second side." ;
num2 = console.nextDouble () ;

System.out.println ("Input your third side." ;
num3 = console.nextDouble () ;

// Determine the perimter of triangle
sum = (num1 + num2 + num3) ;
s=sum/2;

// Determine the area of triangle
area = Math.sqrt (s * (s - num1) * (s - num2) * (s - num3)) ;

// Output the results
System.out.print (" The side of the trangle are " + num1) ;
System.out.println (" and " + num2 +" and " + num3 + " nThe perimeter is " + sum) ;
System.out.print (" The area of the triangle is " + area) ;
}
}

0 votes
Facebook Twitter

ytricky   Germany. Feb 20 2011 20:25. Posts 600

http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html

at the bottom of the page is an example of how to get Userinput from a dialog.

Then just make a Stringtokenizer or use the Strings split method. This can all be easily be found out using the Java Api. You should download it and have it on your desktop. There is also many easy tutorials on the sun page, which are easy to find.


Fudyann   Netherlands. Feb 21 2011 13:45. Posts 704

Why are you learning java? Java will not be seriously used anywhere in the near future. Web applications are being taken over by javascript (cliient+server side) and desktop applications will be .Net or D.


hallizh   Iceland. Feb 21 2011 14:17. Posts 110


  On February 21 2011 12:45 Fudyann wrote:
Why are you learning java? Java will not be seriously used anywhere in the near future. Web applications are being taken over by javascript (cliient+server side) and desktop applications will be .Net or D.


D?

Everyone is a genius. But if you judge a fish on its ability to climb a tree, it will live his whole life believing that it is stupid. -Albert Einstein 

Fudyann   Netherlands. Feb 21 2011 15:01. Posts 704

D is a "modernized" C++ much like C# is.


StArCuE   United States. Feb 21 2011 20:53. Posts 123

It's just what were using in my current class atm.


 



Poker Streams

















Copyright © 2024. LiquidPoker.net All Rights Reserved
Contact Advertise Sitemap