• 100% Satisfaction Guarantee

R.R. Jha, Tutor
Category: Homework
Satisfied Customers: 5471
Experience:  B.Tech
20870358
R.R. Jha is online now

# Java programming

The FAA has recently come under fire for not establishing better technologies to save the lives of passengers on flights unfortunate enough to experience mid-air collisions. These mid-air collisions are the result of distance closing faster than the airplane can be made to react. A brilliant aerospace engineer has designed a passenger jet that constantly monitors radar signatures for input. It calculates the distance between the plane and any other objects within the plane's area of concern up to 3 miles away. Though the plane is agile, it has a threshold of a 10s reaction time. That is to say, the plane can be made to safely avert an object it's headed for collision with so long as it has at least 10s to react. If the pilot has not reacted within 20s the system begins to prepare itself to react on behalf of the pilot. If the plane cannot react by averting disaster, it will eject all 400 passengers from their seats in a safe "cocoon-like" pod that drifts to the earth below using parachutes. That is to say, if for some reason the time to react, based on the plane's speed and object's speed is too short to avert a collision, the plane will launch an escape sequence to save the passengers. Your job is to write a program that receives distance and speed values for the plane and the closest moving object to the plane. The program must calculate the time to impact. If the time to impact, based on the parameters above, is less that 10s then the program will signal the plane to launch the passengers to safety. I need help doing the psuedocode, flowchart and the source code to create this program. I have tried to do them and am getting it wrong. Please help.

Hello!
Welcome!

I'm RRJha and I'd be glad to help with your question. Which programming language does the program need to be in?
Customer: replied 2 years ago.

The langauge is Java. Thank you.

Alright. I can do the pseudocode and java program, but I currently don't have access to flowchart tools. Would that be alright?
Customer: replied 2 years ago.

That is quite alright. Just break the pseudocode down so that I can determine input, output, processing, decision, and any other shape that will need to be used in the flowchart.

Sure. I'll work over this and get back to you within an hour or so.
Customer: replied 2 years ago.

Okay, thank you. You are so kind.

You're welcome :)
Customer: replied 2 years ago.

Attachment: 2013-10-16_191614_buis_305_project2.pdf

I don't know if you can see this, but this is the worked out word problem in which the program will be based on.

Yes, got it.

https://app.box.com/s/k5i5yd7idypi4stp0pch

Let me know if any questions.

If you need help with any other problems, just add 'For RRJha' at the start of your question and I'll get back to you.

Thanks
R.R. Jha, Tutor
Category: Homework
Satisfied Customers: 5471
Experience: B.Tech
Customer: replied 2 years ago.

Do I add the speed of the plane and the other coordinates in the source code?

I also sent Java source code of the program in the zip file. We add speed of the plane and speed of object.
Customer: replied 2 years ago.

Are you saying that it is already done? Do I have to do anything else with this code? Do I need to enter something here

System.out.print("Enter distance of nearest object: ");

You need to enter those values when you compile and run the program. If you've java installed on your system, open command prompt and change directory to where .java file is located. Then type

javac PlaneCollision.java

then type

java PlaneCollision

to run the program.
Customer: replied 2 years ago.

Okay, I'll use IDEone.com to see if it compiles. Thank you.

Customer: replied 2 years ago.

One other question....when compiling, please show me where to put the coordinates and how it should look. Example:

System.out.print("Enter distance of nearest object: "); Does it go between the quotations and does the semicolon stay there?

How should it look if I enter it correctly?

Here is sample run of the program

 Attachments are only available to registered users.Register Here Attachments are only available to registered users.Register Here Attachments are only available to registered users.Register Here View Full Image Attachments are only available to registered users.Register Here

It asked 'Enter distance of object: and I entered 100
Then it asked "Enter speed of the plane: and I entered 5
Then it asked "Enter speed of the object: and I entered 2
Then program outputs "Avert object"

There is also a second run of program where program outputs to eject passengers.
Customer: replied 2 years ago.

Okay, I am not getting it to compile for some reason. This is the code I am using. If there is error here, please tell me where to correct it. Thanks.

import java.util.Scanner;

public class PlaneCollision {

public static void main(String[] args) {

double distance, planeSpeed, objectSpeed;
double timeToCollision;

Scanner input = new Scanner(System.in);
System.out.print:100;
distance = input.nextDouble();
System.out.print:3;
planeSpeed = input.nextDouble();
System.out.print:2;
objectSpeed = input.nextDouble();

timeToCollision = distance / (planeSpeed + objectSpeed);

if (timeToCollision >= 10) {
System.out.println("\nAvert object!");
} else {
System.out.println("\nEject passengers!");
}
}
}

How are you compiling it? System.out.print statements aren't in right syntax.
Customer: replied 2 years ago.

Actually, I am using and online java environment to try to compile that is called IDEone.com. What is the right syntax?

Customer: replied 2 years ago.

If you go to IDEone.com. You can test and run your programs there. That is what I am using. So, if it won't compile because of what I have posted, please tell me how to fix it. Do I need to pay more or something?

You need to spend \$3 to view this post. Add Funds to your account and buy credits.
Customer: replied 2 years ago.

I am getting error. Below is the code I used per your instruction:

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
double distance, planeSpeed, objectSpeed;
double timeToCollision;

Scanner input = new Scanner(System.in);
System.out.print("Enter distance of nearest object: ");
distance = input.nextDouble(100);
System.out.print("Enter speed of the plane: ");
planeSpeed = input.nextDouble(5);
System.out.print("Enter speed of the object: ");
objectSpeed = input.nextDouble(2);

timeToCollision = distance / (planeSpeed + objectSpeed);

if (timeToCollision >= 10) {
System.out.println("\nAvert object!");
} else {
System.out.println("\nEject passengers!");
}
}
}

Here is the error messages I am getting on IDEone.com

Compilation error
Standard input is empty
Compilation info
Main.java:17: error: method nextDouble in class Scanner cannot be applied to given types; distance = input.nextDouble(100);

required:
no arguments found: int reason: actual and formal argument lists differ in length Main.java:19: error: method nextDouble in class Scanner cannot be applied to given types; planeSpeed = input.nextDouble(5);

required:
no arguments found: int reason: actual and formal argument lists differ in length Main.java:21: error: method nextDouble in class Scanner cannot be applied to given types; objectSpeed = input.nextDouble(2);

required:

no arguments found: int reason: actual and formal argument lists differ in length 3 errors

stdout

You're again using wrong syntax. Please copy and paste the code I sent in previous post. In my code, it was

distance = input.nextDouble()

distance = input.nextDouble(100)

Please use what I sent and after pasting, in input (stdin) box just below main code, enter 100 5 2
Customer: replied 2 years ago.

Okay, I did it, but still get error. I know this is getting frustrating, However, if you go test it yourself on IDEone,come, you will see what I am talking about.

Again, this is what I believe you just said to do. This is the code.

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
import java.util.Scanner;

public class PlaneCollision {

public static void main(String[] args) {

double distance, planeSpeed, objectSpeed;
double timeToCollision;

Scanner input = new Scanner(System.in);
System.out.print("Enter distance of nearest object: ");
distance = input.nextDouble(100);
System.out.print("Enter speed of the plane: ");
planeSpeed = input.nextDouble(5);
System.out.print("Enter speed of the object: ");
objectSpeed = input.nextDouble(2);

timeToCollision = distance / (planeSpeed + objectSpeed);

if (timeToCollision >= 10) {
System.out.println("\nAvert object!");
} else {
System.out.println("\nEject passengers!");
}
}
}

Here is the error message:

Compilation error

stdin

compilation info

Main.java:12: error: illegal start of expression import java.util.Scanner; ^

Main.java:12: error: not a statement import java.util.Scanner; ^

Main.java:14: error: illegal start of expression public class PlaneCollision

{ ^ Main.java:37: error: reached end of file while parsing } ^ 4 errors
I meant to copy paste the code I sent in previous post, not the code I sent in PlaneCollision.java file. And don't forget that in input (stdin) box just below main code, enter 100 5 2
Customer: replied 2 years ago.

Okay, I went back and copied the code in the prior message and there was still one error which is below which is this:

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
double distance, planeSpeed, objectSpeed;
double timeToCollision;

Scanner input = new Scanner(System.in);
System.out.print("Enter distance of nearest object: ");
distance = input.nextDouble(100);
System.out.print("Enter speed of the plane: ");
planeSpeed = input.nextDouble(5);
System.out.print("Enter speed of the object: ");
objectSpeed = input.nextDouble(2);

timeToCollision = distance / (planeSpeed + objectSpeed);

if (timeToCollision >= 10) {
System.out.println("\nAvert object!");
} else {
System.out.println("\nEject passengers!");
}
}
}

The errors again are below:

Compilation error

stdin
Standard input is empty

compilation info

Main.java:17: error: method nextDouble in class Scanner cannot be applied to given types; distance = input.nextDouble(100);

^ required:

no arguments found: int reason: actual and formal argument lists differ in length Main.java:19: error: method nextDouble in class Scanner cannot be applied to given types; planeSpeed = input.nextDouble(5);

^ required:

no arguments found: int reason: actual and formal argument lists differ in length Main.java:21: error: method nextDouble in class Scanner cannot be applied to given types; objectSpeed = input.nextDouble(2);

^ required:

no arguments found: int reason: actual and formal argument lists differ in length 3 errors
You're again making the same mistake. input.nextDouble(100) while there should be no 100.

Here is the working program in Ideone

http://ideone.com/TMKI0j
Customer: replied 2 years ago.

I dont get it, I copied the same code from your working one, and still get errors. I didn't change anything at all. I just copied it and pasted it. So I should have gotten the same results that you did. This is bazaar.

Customer: replied 2 years ago.

I just tried another engine to execute the program, and the error I get with this other one is below.

Error - At least one public class is required in main file

Online engines aren't ideal for use. Going back, where did you get the line in bold

System.out.print("Enter distance of nearest object: ");
distance = input.nextDouble(100);
System.out.print("Enter speed of the plane: ");
planeSpeed = input.nextDouble(5);
System.out.print("Enter speed of the object: ");
objectSpeed = input.nextDouble(2);

I've always sent you

System.out.print("Enter distance of nearest object: ");
distance = input.nextDouble();
System.out.print("Enter speed of the plane: ");
planeSpeed = input.nextDouble();
System.out.print("Enter speed of the object: ");
objectSpeed = input.nextDouble();

You notice the difference? I'm not using anything inside the parenthesis. That's where you got error.

I hope that helps as I've working for more than a couple of hours on your issue.
Customer: replied 2 years ago.

Okay again. Here is the code that you showed me that worked: This is what I copied and pasted:

1. /* package whatever; // don't place package name! */

2. import java.util.*;

3. import java.lang.*;

4. import java.io.*;

5. /* Name of the class has to be "Main" only if the class is public. */

6. class Ideone

7. {

8. public static void main (String[] args) throws java.lang.Exception

9. {

10. double distance, planeSpeed, objectSpeed;

11. double timeToCollision;

12. Scanner input = new Scanner(System.in);

13. System.out.print("Enter distance of nearest object: ");

14. distance = input.nextDouble();

15. System.out.print("Enter speed of the plane: ");

16. planeSpeed = input.nextDouble();

17. System.out.print("Enter speed of the object: ");

18. objectSpeed = input.nextDouble();

19. timeToCollision = distance / (planeSpeed + objectSpeed);

20. if (timeToCollision >= 10) {

21. System.out.println("\nAvert object!");

22. } else {

23. System.out.println("\nEject passengers!");

24. }

25. }

26. }

As you can see, there are no characters in the brackets.

Here is the error message.

stdin
Standard input is empty

stdout
Enter distance of nearest object:

stderr

"main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:907) at java.util.Scanner.next(Scanner.java:1530) at java.util.Scanner.nextDouble(Scanner.java:2456) at Ideone.main(Main.java:17)

Customer: replied 2 years ago.
I need for someone to be more complete with the solution, and clear on the issue. I feel as though I am getting the run around here.
Because this time you forgot to enter the input. In input (stdin) box below main code, type 100 5 2
Customer: replied 2 years ago.

You said not to put 100: Your response below:

System.out.print("Enter distance of nearest object: ");
distance = input.nextDouble(100);
System.out.print("Enter speed of the plane: ");
planeSpeed = input.nextDouble(5);
System.out.print("Enter speed of the object: ");
objectSpeed = input.nextDouble(2);

I've always sent you

System.out.print("Enter distance of nearest object: ");
distance = input.nextDouble();
System.out.print("Enter speed of the plane: ");
planeSpeed = input.nextDouble();
System.out.print("Enter speed of the object: ");
objectSpeed = input.nextDouble();

So if I am to put 100, 5 and 2 where do I put it. Your confusing me because you just said that I was making the same mistake by putting the 100 and now your saying that I need to put it. If so, show me exactly where. Am, I missing something. Sorry for the lack of understanding

You need to spend \$3 to view this post. Add Funds to your account and buy credits.
Customer: replied 2 years ago.

Phew thank you, it worked.

You're welcome!
Bonus is appreciated. Option to add bonus would be where you left the rating for the answer. Somewhere around top of this page.

Thanks
Customer: replied 2 years ago.

Okay. I'll look for it.

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.

### What Customers are Saying:

• Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
< Previous | Next >
• Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
• This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
• Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
• I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
• Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
• Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
• He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here. Diane Dallas, TX

• ### LogicPro

#### Satisfied Customers:

4925
Expert in Java C++ C C# VB Javascript Design SQL HTML
< Last | Next >

### LogicPro

#### Satisfied Customers:

4925
Expert in Java C++ C C# VB Javascript Design SQL HTML

### Manal Elkhoshkhany

#### Satisfied Customers:

4538
More than 5000 online tutoring sessions.

### Linda_us

#### Satisfied Customers:

3138
Post Graduate Diploma in Management (MBA)

### Chris M.

#### Satisfied Customers:

2602
Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)

### F. Naz

#### Satisfied Customers:

2126
Experience with chartered accountancy

### Bizhelp

#### Satisfied Customers:

1887
Bachelors Degree and CPA with Accounting work experience

### Seanna

#### Satisfied Customers:

1781
3,000+ satisfied customers, all topics, A+ work