The Artima Developer Community
Sponsored Link

Java Answers Forum
Help please><

2 replies on 1 page. Most recent reply: Sep 24, 2006 4:21 AM by Fiona Lee

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Fiona Lee

Posts: 2
Nickname: pheeyona
Registered: Sep, 2006

Help please>< Posted: Sep 22, 2006 10:23 PM
Reply to this message Reply
Advertisement
I'm a high school student that's learning Java now, and we have all these huge assignments to do, but school just started and it takes time and practice to remember a lot of codes and stuff, yet I think it's going way too fast. So we did one project about linear equation, this was what the teacher told me:
 /* YOUR PROGRAM ASSUMES THAT THE SLOPES AND Y-INTERCEPTS ARE INTEGERS
  * EVEN IF THEY WERE INTEGERS, THE COORDINATES OF THE POINT OF INTERSECTION ARE NOT NECESSARILY INTEGERS
  * ALTHOUGH YOUR COORDINATES ARE DOULBES, THEY ARE CALCULATED FROM INTEGER.
  * THEREFORE THEY ARE INTEGERS CAST INTO DOUBLES. THE DECIMAL PART IS DISCARDED
  * SO YOUR ANSWER IS WRONG IF THE COORDINATES OF THE SOLUTION ARE NOT INTEGERS
  *
  * YOUR CODE IS HARD TO READ BECAUSE THERE ARE NO COMMENTS, ALMOST NO INDENTING, AND NO USE OF BRACES FOR if CODE
  */
  
 public class Line
 {
 	public static void main(String args[])
 {
 	int slope1=Jin.readInt("Type first slope here ");
 	int intercept1=Jin.readInt("Type first intercept here ");
 	int slope2=Jin.readInt("Type second slope here ");
 	int intercept2=Jin.readInt("Type second intercept here ");
 	int bslope1=slope1;
 	int bintercept1=intercept1;
 
/* YOU DID NOT TEST FOR PARALLEL OR IDENTICAL LINES
 *
 * WHEN POSSIBLE, IT IS CLEARER IF YOU COLLECT ALL THE DATA FOR A LINE OF OUTPUT
 * AND DISPLAY IT ALL IN A println STATEMENT, RATHER THAN MULTIPLE SEPARATED print STATEMENTS
*/
 	System.out.print("The intersection point between the lines y = ");
 	if (slope1!=1)
 	System.out.print(slope1);
 	System.out.print("x + " +intercept1+ " and y = ");
 	if (slope2!=1)
 	System.out.print(slope2);
 	System.out.print("x + " +intercept2+ " is (");
 	intercept2=intercept2-intercept1;
 	intercept1=0;
 	slope1=slope1-slope2;
 	slope2=0;
 	intercept2=intercept2/slope1;
 	slope1=1;
 	double xcoordinate=intercept2; 
 	double ycoordinate=bslope1*xcoordinate+bintercept1;
 	System.out.println(+xcoordinate+ "," +ycoordinate+ ")." );
 	
 	}
 	
 	
 }


I don't understand what he's trying to say...and I'm really dumb, am I suppose to change int to double because I can't really assume that the numbers are integers...or what?


Boston Thornton

Posts: 8
Nickname: preston
Registered: Sep, 2006

Re: Help please>< Posted: Sep 23, 2006 2:37 PM
Reply to this message Reply
Okay, I can anwser! From a math stand point, using a (int) data type assumes that every number calculated will result in a whole number (1, 123, 9999929938, etc). Well what about a calculation like 3/2? Hey, that equals 1.5. WOW! You program will present only "1." Okay now it's 15 years in the future and your working for NASA, doing space shuttle re-entry plans. Your program has just truncated some very important information for landing. The shuttle will land in Russia istead of Florida because the ".5" was lost. In short the (int) data type was not big enough to hold 1.5 but only 1. Using the (double) data type allows you to hold the fractional numbers. So by using (double) whenever doing a calculation is a safe bet (i.e look at changing the slopes for example from (int) to (double)). And, no YOU ARE NOT DUMB! You are learning and you will alway continue in this time of life. I hope that helps.

Fiona Lee

Posts: 2
Nickname: pheeyona
Registered: Sep, 2006

Re: Help please>< Posted: Sep 24, 2006 4:21 AM
Reply to this message Reply
Yeah it helped a lot! Thank you!!

Flat View: This topic has 2 replies on 1 page
Topic: Method problems Previous Topic   Next Topic Topic: New to the art.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use