473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Student programmer - need help :(

Steel546
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
  1. package *****;
  2.  
  3.  
  4.  
  5. public class fighterJet {
  6.  
  7.     double setRange=0; // number of miles flown before running out of fuel
  8.     double distanceTraveled=0; // how far jet has flown since last refuel
  9.     double xOffset=0; // how far east, west using negative numbers
  10.     double yOffset=0; // how far north, south using negative numbers
  11.     int numMisslesRemaining=0; // number of missles remaining
  12.  
  13.     public fighterJet (double setRange, int setNumMissles) {
  14.  
  15.  
  16.  
  17.     }
  18.  
  19.     private boolean outOfFuel(){
  20. if (setRange == 0) {
  21.     boolean outOfFuel = true;
  22.     System.out.println("Oh no, you ran out of fuel!");}
  23. if (setRange != 0){
  24.  
  25.     }
  26.  
  27.  
  28.   }
  29.     public void fly(double distanceX, double distanceY){
  30.  
  31.         double x = distanceX - xOffset;
  32.         double y = distanceY - yOffset;
  33.  
  34.         double current = Math.sqrt((x*x)+(y*y));
  35.         System.out.println(current);
  36.  
  37.         distanceTraveled += current;
  38.  
  39.     }
  40. }
  41.  
  42.  
  43. package *****;
  44.  
  45. import java.util.Scanner;
  46.  
  47.  
  48. public class *****SecretMission {
  49.  
  50.  
  51.     public static void main(String[] args) {
  52.  
  53. // create scanner for input
  54.         Scanner input = new Scanner (System.in);
  55. //obtain user input
  56.         System.out.println("Enter your destination coordinates");
  57.         double 
  58.  
  59.  
  60.    }
  61.  
  62. }
  63.  
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 1920
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
r035198x
13,262 8TB
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
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
r035198x
13,262 8TB
Like I said, it's not allowed here so don't do it again.
Mar 10 '09 #5
JosAH
11,448 Expert 8TB
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
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
  1. private boolean outOfFuel()
  2. {
  3. .
  4. .
  5. .
  6. }
  7.  
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
  1.   }
  2.     private boolean outOfFuel(){
  3.         return (true);
  4.  
  5.     }
... 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
r035198x
13,262 8TB
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
JosAH
11,448 Expert 8TB
@Steel546
I'd expect a method like this then:

Expand|Select|Wrap|Line Numbers
  1. private boolean outOfFuel() {
  2.    return range >= distanceTraveled;
  3. }
  4.  
btw, nothing is messing with you; read the tutorials because you're having basic language problems.

kind regards,

Jos
Mar 10 '09 #9
It's alright, pretty sure I got this figured out now.

Expand|Select|Wrap|Line Numbers
  1. package *****;
  2.  
  3.  
  4.  
  5. public class fighterJet {
  6.  
  7.   private double range; // number of miles flown before running out of fuel
  8.   private double distanceTraveled; // how far jet has flown since last refuel
  9.   private double xOffset; // how far east, west using negative numbers
  10.   private double yOffset; // how far north, south using negative numbers
  11.   private int numMisslesRemaining; // number of missles remaining
  12.  
  13.  
  14.  
  15.     public fighterJet(double setRange, int setNumMissles) {
  16.  
  17.       range = setRange;
  18.       numMisslesRemaining = setNumMissles;
  19.  
  20.     }
  21.     private boolean outOfFuel(){
  22.  
  23.         if (distanceTraveled > range){
  24.             return true;
  25.         }else{
  26.             return false;
  27.         }
  28.  
  29.   }
  30.  
  31.     public void fly(double distanceX, double distanceY){
  32.  
  33.         double x = distanceX - xOffset;
  34.         double y = distanceY - yOffset;
  35.  
  36.         double current = Math.sqrt((x*x)+(y*y));
  37.         System.out.println(current);
  38.  
  39.         distanceTraveled = distanceTraveled + current;
  40.  
  41.         if (outOfFuel()){
  42.             System.out.println("You are out of fuel. Goodbye.");
  43.         }else{
  44.             System.out.println("You have reached your destination");
  45.         }
  46.  
  47.         xOffset = distanceX;
  48.         yOffset = distanceY;
  49.  
  50.  
  51.     }
  52.  
  53.     public void fireMissile(){
  54.  
  55.         if (numMisslesRemaining > 0){
  56.             System.out.println("Missle away!");
  57.             numMisslesRemaining -= 1;}
  58.             else
  59.                if (numMisslesRemaining == 0){
  60.                    System.out.println("You have no missles remaining");
  61.                }
  62.  
  63.         }
  64.  
  65.  
  66. }
  67.  
  68.  
  69. package *****;
  70.  
  71.  
  72. public class *****SecretMission {
  73.  
  74.  
  75.     public static void main(String[] args) {
  76.  
  77.     fighterJet striker1 = new fighterJet(100,2);
  78.     fighterJet striker2 = new fighterJet(20,1);
  79.  
  80.     striker1.fly(20, 10);
  81.     striker1.fireMissile();
  82.  
  83.  
  84.     striker1.fly(15, 8);
  85.     striker1.fireMissile();
  86.  
  87.     striker2.fly(10,15);
  88.     striker2.fireMissile();
  89.  
  90.     striker2.fly(20, 20);
  91.     striker2.fireMissile();
  92.  
  93.  
  94.  
  95.  
  96.     }
  97. }
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
r035198x
13,262 8TB
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
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
r035198x
13,262 8TB
Well you could simply make the changes you are trying to describe and run it to find out for yourself.
Mar 12 '09 #13
JosAH
11,448 Expert 8TB
@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

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mojo | last post by:
Ok, I don't want to much help but I need a push. I am supposed to write a program with 3 classes: 1. Controlling class 2. Student class 3. Grades class Controlling class instantiates a student...
45
by: Joh | last post by:
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = would like to produce : , , , ,
3
by: bhavin | last post by:
really for me it's gratefull if i get this answer my question is that why certain category of operator can't be overloaded please explain me
13
by: Pradeep Vasudevan | last post by:
hai i am a student and need to write a simple web crawler using python and need some guidance of how to start.. i need to crawl web pages using BFS and also DFS... one using stacks and other...
2
by: ammad | last post by:
HI , How r u All.............im an undergraduate student and need some help in php...is it possilbel to bypass Database Interface using php so tht i can pose queries in the query processor of the...
1
by: flavourofbru | last post by:
Hi, I am stuck at a major part of the code in VC++. My algorithm is as follows: f_name = load(filename); //this also loads a text file. The text files contains numbers sepearted by tab....
0
by: tim | last post by:
Hi, I have a program of about 300 lines of code that I wrote in AutoHotKeys. I am looking for someone who might be interested in making a little $ to help me bring this program into a mac...
2
by: aszush | last post by:
//Title: Programming Assignment 1 //Version: //Copyright: Copyright (c) 1999 //Author: Andrew //Company: //Description: Computes employee's weekly gross and net pay....
9
by: lilchiko1286 | last post by:
I am taking an intro to C++ course in college. I was assigned a project that i must complete on MS Visual Studio in where I am supposed to prompt the user for a name and then a letter and output...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.