Triangle Area Program

I need to add a floating decimal and a if statement to this program. Can anyone help me out? I am not sure if the program will compile and run as is.

// import statement

import java.util.Scanner;

/*

* Author: Daniel Wood

* Date: 2006.01.26

* Revision History: N/A

*/

public class TriangleArea

{

static int number_1 = 0; //stores the first value entered (Base)

static int number_2 = 0; //stores the second value entered (Height)

static int sum = 0; //strores the value of .5 * number_1(Base) * number_2(Height)

public static void main (String args[] ) {

Scanner myScannerReference = new Scanner(System.in );

//Instansiates scanner class

// Read in the data

System.out.print("Please enter the base: ");

number_1 = myScannerReference.nextInt();

System.out.print("Please enter the height: ");

number_2 = myScannerReference.nextInt();

//Compute the sum

sum = number_1 * number_2 * (1/2);

// Print the result

System.out.println("The Area of " + number_1 + " and " + number_2 + " is " + sum );

// Outline the ASCII Triangle and display its dimensions

System.out.print(" *");

System.out.print(" * *");

System.out.print(" * *");

System.out.print("Height" +"**");

System.out.print("number_1"+ "**");

System.out.print(" **");

System.out.print(" *******");

System.out.print("Base");

System.out.print(number_2);

} // end method main()

} // end class TriangleArea

[1576 byte] By [Dwooda] at [2007-10-2 10:59:52]
# 1

> I am not sure if the program will compile and run as is.

You can compile it by going to the directory that contains

TriangleArea.java and executing the command

javac -classpath . TriangleArea.java

It's a good idea to use the "code" button (right above where you

composed your post). Select the code and click the code button -

this will ensure that the code is formatted properly.

If you get an error from the compiler that you can't understand, post it

here (cut and paste so there aren't any typos). If the error message

includes a line number, don't forget to say which line of your code

it is referring to.

pbrockway2a at 2007-7-13 3:28:43 > top of Java-index,Java Essentials,New To Java...
# 2
'javac' is not recognized as an internal or external command,operable program or batch file.I have made the varable for javac but am unable to get it to run on my pc
Dwooda at 2007-7-13 3:28:43 > top of Java-index,Java Essentials,New To Java...
# 3

then forget about code for now - this is the first step in learning to program, running the complier. these are the steps you need to accomplish:

* download the JDK for your pc

* extract it to your pc

* set the path variable for your pc to include the "bin" dirsctory (somewhere under the folder you extracted too).

* test it by oping a command line iterface and typeing java - you should get a list of permitted command arguments.

Ken_Sa at 2007-7-13 3:28:43 > top of Java-index,Java Essentials,New To Java...
# 4
I have extracted the files and created and enviornmental variable:Java_Homeand with a path name of:C:\Program Files\Java\jdk1.5.0_04and I still get that error message
Dwooda at 2007-7-13 3:28:43 > top of Java-index,Java Essentials,New To Java...
# 5
I think your path should be:C:\Program Files\Java\jdk1.5.0_04\bin
tim_marshalla at 2007-7-13 3:28:43 > top of Java-index,Java Essentials,New To Java...
# 6
I am using this path name:C:\Program Files\Java\jdk1.5.0_04\binand still get the error message.
Dwooda at 2007-7-13 3:28:43 > top of Java-index,Java Essentials,New To Java...
# 7
Java_Home?No. On Windows you want to add it to your path.
Dwooda at 2007-7-13 3:28:43 > top of Java-index,Java Essentials,New To Java...
# 8
Which one would that be for windows?
Dwooda at 2007-7-13 3:28:43 > top of Java-index,Java Essentials,New To Java...
# 9
When you made the environment changes did you open a new cmd window or are you still using the old one?
Dwooda at 2007-7-13 3:28:43 > top of Java-index,Java Essentials,New To Java...
# 10
Im not sure what a cmd variable is so I believe I am still using my old one.
Dwooda at 2007-7-13 3:28:43 > top of Java-index,Java Essentials,New To Java...
# 11
> Im not sure what a cmd variable is so I believe I am> still using my old one.Did you open a new DOS window.
Dwooda at 2007-7-13 3:28:44 > top of Java-index,Java Essentials,New To Java...
# 12
i typed in set path and .java is not showing up as an extension
Dwooda at 2007-7-13 3:28:44 > top of Java-index,Java Essentials,New To Java...
# 13

> i typed in set path and .java is not showing up as an

> extension

Okay.

Please do the following.

Close the DOS/cmd window you are working with.

Open a new one.

Type path and hit enter.

What does that say?

If Java does not show up then type the following

path=c:\Program Files\Java\jdk1.5.0_04\bin

and hit enter. This will set you path for THIS WINDOW ONLY.

Now type javac and hit enter.

Does that work? If not then you have the wrong path to your install. If it does work then we just need to set your path permanently.

Dwooda at 2007-7-13 3:28:44 > top of Java-index,Java Essentials,New To Java...
# 14
alright it was not there and then I typed the command and it worked. How do I make it permanent?
Dwooda at 2007-7-13 3:28:44 > top of Java-index,Java Essentials,New To Java...
# 15

Go into your system properties (right click my computer or Start -> Settings - > Control Panel -> System)

Choose the Advanced Tab

Choose the Environment Variables.

Edit the user (or system if you have multiple accounts) variable PATH/path

Add that directory to the end of the path. The path seperator is a semi colon.

So if you have a path like this

C:\perl

Then the new path will be

C:\perl;c:\Program Files\Java\jdk1.5.0_04\bin

Then click Ok. Ok again. Apply. Then ok.

Then open a new window. (When you make changes to the path it does NOT update existing cmd shells)

PS cmd is the DOS window... and the reason I am not calling it DOS before is that it actually isn't DOS just looks and smells the same.

at 2007-7-20 20:58:51 > top of Java-index,Java Essentials,New To Java...
# 16
Oh and when the compile works I am not sure much about your logic but I am off for dinner now. I would suggest for help on the actual program you take a look at this guy's triangle thread http://forum.java.sun.com/thread.jspa?threadID=704266&tstart=0
at 2007-7-20 20:58:51 > top of Java-index,Java Essentials,New To Java...
# 17
JAVA_HOME should be set toC:\Program Files\Java\jdk1.5.0_04but you should add%JAVA_HOME%\bin to your PATHsome programs (tomcat for instance) need JAVA_HOME set this way.
dmbdmba at 2007-7-20 20:58:51 > top of Java-index,Java Essentials,New To Java...