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. -
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.
13 1920
Actually... I don't even think I need a scanner. I think they just want to see it inside the program... hmm.
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.
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.
Like I said, it's not allowed here so don't do it again.
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)
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." - 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... -
}
-
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.
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.
@Steel546
I'd expect a method like this then: - 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
It's alright, pretty sure I got this figured out now. - 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?
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.
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.
Well you could simply make the changes you are trying to describe and run it to find out for yourself.
@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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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 :
, , , ,
|
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
|
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...
|
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...
|
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....
|
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...
|
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....
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
| |