User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 426,905 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,300 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 5086 | Replies: 4
Reply
Join Date: Aug 2004
Posts: 771
Reputation: OurNation is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 8
OurNation's Avatar
OurNation OurNation is offline Offline
Master Poster

JAVA help

  #1  
Jan 28th, 2005
Whats wrong with this im just dumb and couldnt figure it out help please

//SLOPE

import java.io.*;
public class SLOPE {
public static void main(String args [ ]) {
int Y2, Y1, X2, X1;
BufferedReader reader;

reader = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.print("\nY2 =");
Y2 = Integer.parseInt(reader.readLine( ));
System.out.print("Y1 = ");
Y1 = Integer.parseInt(reader.readLine( ));
System.out.print("X2 = ");
X2 = Integer.parseInt(reader.readLine( ));
System.out.print("X1 = ");
X1 = Integer.parseInt(reader.readLine( ));
reader.close ( );
}
catch (IOException ioe) {
System.out.println("An error accoured while calculating this equation try again");
}
catch (NumberFormatException nfe) {
System.out.println("An error accoured while calculating this equation try again");
}

System.out.println( "The slope is" + ( (Y2 - Y1) / (X2 - X1)));
}
}
PETA People for the Eating of Tasty Animals.


FireFox
Hijack This
Ad-Aware
Hijack this tutorial
Microsoft AntiSpyware
CompUchat
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: JAVA help

  #2  
Jan 29th, 2005
wrong forum would be the first thing that's wrong with it...

You don't need that reader either.
And then your calculation will of course always yield an integer value as you're working with only integers.
Reply With Quote  
Join Date: Aug 2004
Posts: 771
Reputation: OurNation is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 8
OurNation's Avatar
OurNation OurNation is offline Offline
Master Poster

Re: JAVA help

  #3  
Jan 29th, 2005
which reader? Im kinda confused and lost
PETA People for the Eating of Tasty Animals.


FireFox
Hijack This
Ad-Aware
Hijack this tutorial
Microsoft AntiSpyware
CompUchat
Reply With Quote  
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

Re: JAVA help

  #4  
Feb 17th, 2005
I rewrote it, but you really need to work on your conventions: indenting, and naming.

import java.io.*;

  public class Slope
  {
     public static void main(String args [ ]) {
     
     	double y2, y1, x2, x1;
 	y2 =0;
	y1 =0;
	x2 =0;
	x1 =0;

	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

	try 
	{
		System.out.print("\nY2 =");
		y2 = Double.parseDouble(reader.readLine( ));
		
		System.out.print("Y1 = ");
		y1 = Double.parseDouble(reader.readLine( ));
		
		System.out.print("X2 = ");
		x2 = Double.parseDouble(reader.readLine( ));
		
		System.out.print("X1 = ");
		x1 = Double.parseDouble(reader.readLine( ));
		
		reader.close ( );
	}
	catch (IOException ioe) 
	{
		System.out.println("An error accoured while calculating this equation try again");
	}
	catch (NumberFormatException nfe) 
	{
		System.out.println("An error accoured while calculating this equation try again");
	}
	
	System.out.println( "The slope is " + getSlope(y2,y1,x2,x1));
   }
   
   public static double getSlope(double y1, double y2, double x1, double x2)
	{
		double yValue = y2-y1;
		double xValue = x2-x1;
		double slope = yValue/xValue;
		
		return slope;
	}
}
Reply With Quote  
Join Date: Aug 2004
Posts: 771
Reputation: OurNation is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 8
OurNation's Avatar
OurNation OurNation is offline Offline
Master Poster

Re: JAVA help

  #5  
Feb 17th, 2005
//SLOPE

import java.io.*;
public class SLOPE  {
        public static void main(String args [ ]) {
                //Where the variables are declared
                String sone;
                String stwo;
                String sthree;
                String sfour;
                float one, two, three, four;
                double rise, run;
                BufferedReader reader;
                reader  =  new BufferedReader(new InputStreamReader(System.in));

                System.out.print("\nThe first x = ");
                // Where the user input is aquired
                try   {
                        sone = reader.readLine( );
                        System.out.print("The first y = ");
                        stwo = reader.readLine( );
                        System.out.print("The second x = ");
                        sthree = reader.readLine( );
                        System.out.print("The second y = ");
                        sfour = reader.readLine( );
                        //Converting the user input to floating numbers allowing negitives decimals ect to be used
                        one = Float.parseFloat(sone) ;
                        two = Float.parseFloat(stwo) ;
                        three= Float.parseFloat(sthree) ;
                        four = Float.parseFloat(sfour) ;

                        rise = four - two;
                        run = three - one;



                        //The answers
                        System.out.println("The rise = " + rise) ;
                        System.out.println("The run = " + run );
                        System.out.println("The slope is ");
                        System.out.println(rise);
                        System.out.println("____");
                        System.out.println(run);

                        reader.close ( );
                        //The exceptions if an error accours
                }
                catch (IOException ioe) {
                        System.out.println("Error");
                }
                catch (NumberFormatException nfe) {
                        System.out.println("Error");
                }


        }

}

I reworte it a long time ago its in the code snipets under find slope rise and run but thanks for posting that anyway :lol: my next project is much more complex and ill post it here when im done



EDIT:The indenting thing is from not wraping the code tags around it it removed the idents i guess when i posted it :o
Last edited by OurNation : Feb 17th, 2005 at 8:27 pm. Reason: forgot somethin'
PETA People for the Eating of Tasty Animals.


FireFox
Hijack This
Ad-Aware
Hijack this tutorial
Microsoft AntiSpyware
CompUchat
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 11:15 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC