446,341 Members | 1,376 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,341 IT Pros & Developers. It's quick & easy.

# Student programmer - need help :(

 P: 25 Let me begin, I am a college student in a basic programming class and I honestly have a tough time learning Java. I'm here because I have a lab I'm trying to do and it's like I have a hard time filling in the blanks because our teachers don't teach us, they just say "go". So, any offering help is much obliged. My lab link is located http://www.cse.unt.edu/~ecelikel/spr...ments/lab4.doc. It's a .doc file. I'm supposed to create two files for a jet fighter simulation and I'm a little stuck as I'm not very experience with the scanner class or with doing some methods. Yes, I've read the Sun Tutorials, I have them open, just I don't understand sometimes. It's like I'm trying to read latin. But here's what I have so far. The asterisks are my name, just choose not to display. Expand|Select|Wrap|Line Numbers package *****;       public class fighterJet {       double setRange=0; // number of miles flown before running out of fuel     double distanceTraveled=0; // how far jet has flown since last refuel     double xOffset=0; // how far east, west using negative numbers     double yOffset=0; // how far north, south using negative numbers     int numMisslesRemaining=0; // number of missles remaining       public fighterJet (double setRange, int setNumMissles) {           }       private boolean outOfFuel(){ if (setRange == 0) {     boolean outOfFuel = true;     System.out.println("Oh no, you ran out of fuel!");} if (setRange != 0){       }       }     public void fly(double distanceX, double distanceY){           double x = distanceX - xOffset;         double y = distanceY - yOffset;           double current = Math.sqrt((x*x)+(y*y));         System.out.println(current);           distanceTraveled += current;       } }     package *****;   import java.util.Scanner;     public class *****SecretMission {         public static void main(String[] args) {   // create scanner for input         Scanner input = new Scanner (System.in); //obtain user input         System.out.println("Enter your destination coordinates");         double         }   }   At "private boolean outOfFuel()" it says I'm missing a return value, and I can't figure out how to put that in. Other than that, I'm still working on it as you read this trying to add more and figuring out how to organize all of this. Thank you very much for any help at all. Mar 10 '09 #1
13 Replies

 P: 25 Actually... I don't even think I need a scanner. I think they just want to see it inside the program... hmm. Mar 10 '09 #2

 10K+ P: 13,264 You are getting the error because you declare the method as returning a boolean value and yet you don't return anything in that method. The compiler doesn't like that. P.S Read the posting guidelines about how to use code tags and how not to post your content in bold for no apparent reason. Mar 10 '09 #3

 P: 25 Well I posted in bold or else everything just kind of runs together, so I thought I'd make it obvious. I dunno, it just bothered me. Heh. Mar 10 '09 #4

 10K+ P: 13,264 Like I said, it's not allowed here so don't do it again. Mar 10 '09 #5

 Expert 10K+ P: 11,448 I fixed it: added code tags and removed the darn bold attributes; they hurt my eyes. btw, when you type "boolean myMethod() { ... }" you promise that your method will return a boolean value (true or false); when there's no return statement to be seen your compiler will complain. kind regards, Jos (moderator) Mar 10 '09 #6

 P: 25 So, my lab says... "Create a private method called outOfFuel of type boolean. It returns true if the distance the jet has traveled has exceeded its range. It returns false otherwise." Expand|Select|Wrap|Line Numbers private boolean outOfFuel() { . . . }   But if I type that "template" in, it says "missing return value"... I'm pretty sure my lab is messing with me. So creating a private boolean method... Expand|Select|Wrap|Line Numbers   }     private boolean outOfFuel(){         return (true);       } ... Unfortunately, I don't know how that helps my project. At least I don't have any errors. :/... and I keep going. Mar 10 '09 #7

 10K+ P: 13,264 Don't keep going! Stop and take some time to go through Sun's tutorial first. Understand the basic principles of what Java programming is all about before you start working on your lab. Mar 10 '09 #8

 Expert 10K+ P: 11,448 @Steel546 I'd expect a method like this then: Expand|Select|Wrap|Line Numbers private boolean outOfFuel() {    return range >= distanceTraveled; }   btw, nothing is messing with you; read the tutorials because you're having basic language problems. kind regards, Jos Mar 10 '09 #9

 P: 25 It's alright, pretty sure I got this figured out now. Expand|Select|Wrap|Line Numbers package *****;       public class fighterJet {     private double range; // number of miles flown before running out of fuel   private double distanceTraveled; // how far jet has flown since last refuel   private double xOffset; // how far east, west using negative numbers   private double yOffset; // how far north, south using negative numbers   private int numMisslesRemaining; // number of missles remaining           public fighterJet(double setRange, int setNumMissles) {         range = setRange;       numMisslesRemaining = setNumMissles;       }     private boolean outOfFuel(){           if (distanceTraveled > range){             return true;         }else{             return false;         }     }       public void fly(double distanceX, double distanceY){           double x = distanceX - xOffset;         double y = distanceY - yOffset;           double current = Math.sqrt((x*x)+(y*y));         System.out.println(current);           distanceTraveled = distanceTraveled + current;           if (outOfFuel()){             System.out.println("You are out of fuel. Goodbye.");         }else{             System.out.println("You have reached your destination");         }           xOffset = distanceX;         yOffset = distanceY;         }       public void fireMissile(){           if (numMisslesRemaining > 0){             System.out.println("Missle away!");             numMisslesRemaining -= 1;}             else                if (numMisslesRemaining == 0){                    System.out.println("You have no missles remaining");                }           }     }     package *****;     public class *****SecretMission {         public static void main(String[] args) {       fighterJet striker1 = new fighterJet(100,2);     fighterJet striker2 = new fighterJet(20,1);       striker1.fly(20, 10);     striker1.fireMissile();         striker1.fly(15, 8);     striker1.fireMissile();       striker2.fly(10,15);     striker2.fireMissile();       striker2.fly(20, 20);     striker2.fireMissile();             } } In my fly method, when I set the xOffset/yOffset equal to the distanceX/distanceY, will that update that x and y values if it runs through again? Mar 12 '09 #10

 10K+ P: 13,264 What do you mean? You have double x = distanceX - xOffset; If you change any of xOffset or distanceX then surely your x value will change. Mar 12 '09 #11

 P: 25 For instance if I run the program twice so the jet will "run out of fuel". When I place xOffset = distanceX after running the math portion, the next time I run the program, it'll be the "new" distanceX subtracting the previous distance as a "point"... man, this is hard to describe. Mar 12 '09 #12

 10K+ P: 13,264 Well you could simply make the changes you are trying to describe and run it to find out for yourself. Mar 12 '09 #13

 Expert 10K+ P: 11,448 @Steel546 This is the core of your problem: if you find it hard to describe it'll be even harder to implement. Try to find an easier description first. kind regards, Jos Mar 12 '09 #14