Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NetBeans for JavaFX I have to have this program, originally written in Java(console based), run in Java FX with pop up windows and buttons/text based

NetBeans for JavaFX I have to have this program, originally written in Java(console based), run in Java FX with pop up windows and buttons/text based input for choices/input.

image text in transcribedimage text in transcribed

image text in transcribedimage text in transcribed

You have to be able to create your vehicle with the user inputting the maximum fuel capacity and miles per gallon, and allow the user to travel between cities and refuel at locations with a gas station.

image text in transcribed

This is what I have so far but I'm stuck. My main question is how can I get the inputs for Maximum fuel capacity and miles per gallon be inputted by the user and correctly assign the values? Any additional help is appreciated

App.java Location.java Vehicle.java Miniproject.java tory I - ? B ckage com.mycompany.miniproject; port java.util.ArrayList; port java.util.Scanner; blic class Miniproject public static void main(String[] args) \{ Scanner s = new Scanner(source: System.in); ArrayList location = new ArrayList () ; location.add (new Location (name: "Cleveland", w: 0, 7:0,6as_Station:true)) ; location.add (new Location (name: "North Pole", w: 500,y: -100,6as_Station:true)) ; location.add (new Location (name: "Campbell Hill", w: -50,y: -50,Gas_Station:false)); location.add (new Location (name: "Tokyo", w: -100 , 7:1000, Gas_Station:true)) ; location.add (new Location (name: "Chicago", w: 200,y:75,6as station:true)) ; location.add (new Location(name: "Erie PA", w: 150,7:0,6as_Station:true)) ; location.add(new Location (name: "Allegheny Nation Forrest", w: 300,y: -75,Gas_Station:false)); System.out.println(x: "Please create your vehicle."); System.out.print(s: "Please enter your vehicle's maximum fuel capacity(in gallons):"); double mfc=s.nextDouble (); System.out.print(s: "Please enter your vehicles fuel efficeny rate in MPG:"); double mpg=s.nextDouble () ; Vehicle vehicle = new Vehicle((Location) location.get (inder:0), mfc,cf: mfc,mpg); int option; do \{ System.out.println(" Current Location: " +vehicle.getLocation().getName ()); System.out.println("Current Fuel: " +vehicle.getCf()); System.out.println(x: "l] Drive"); System.out.println (x: "2] Get gas"); System.out.println(w: "3] Exit"); System.out.println(x: "Please enter the number associated with your option: "); option = s.nextInt () ; switch (option) \{ case 1: System.out.println(s: "Where do you want to drive?: "); System.out.println(m: "l] North Pole"); System.out.println(x: "2] Campell Hill"); System.out.println(s: "3] Tokyo"); System.out.println(x: "4] Chicago"); System.out.println(x: "5] Erie PA"); System.out.println(m: "6] Allegheny Nation Forest"); int terminus_option=s.nextInt () ; Location terminus = null; switch (terminus_option) \{ case 1: terminus = (Location) location.get (inder: 1 ); break; case 2: terminus = (Location) location.get (inder: 2); break; case 3 : terminus = (Location) location.get (inder: 3); terminus = (Location) location.get (inder: 2); break; case 3: terminus = (Location) location.get (inder: 3 ); break; case 4: terminus = (Location) location.get (inder: 4); break; case 5: terminus = (Location) location.get (inder: 5); break; case 6 : terminus = (Location) location.get (inder: 6); break; default: System.out.println (x: "No."); break; \} if (terminus !=null) \{ vehicle. drive (terminus); \} break; case 2: vehicle.refuel () ; break; case 3: System.out.println (x: "Exiting..."); break; default: System. out.println (x: "Nope."); break; (option !=3); package com.mycompany.miniproject; public class Vehicle \{ private Location location; private double mfc; private double cf; private double mpg; public Vehicle(Location start, double mfc, double cf, double mpg) \{ this.location = start; this.mfc =mfc; this.cf =cf; this.mpg =mpg; \} public Location getLocation() \{ return location; \} public double getcf() \{ return cf; \} Qoverride public String tostring() \{ return "Vehicle\{" + "location=" + location + ", mfc=" + mfc + ", cf=" + cf + ", mpg=" + mpg + " "; \} public void drive(Location terminus) \{ double xl= location.getX () ; double y1 = location.getY(); double x2 = terminus.getX(); double y2 = terminus.getY(); double distance= Math.sqrt (Math.pow ((x2x1),b:2)+Mathpow((y2y1),b:2)); double rf = distance/mpg; if (Cf>=rf) \{ cf=cf-rf; this.location=terminus; System.out.println(w: "We've made it!"); \} else \{ System.out.println(x: "We don't have enough fuel."); \} \} public void refuel() \{ if (location.isGas_Station()==true) \{ cf=mfC; System.out.println(x: "Refuel successful!"); \} else \{ System.out.println(x: "This place doesn't havea gas station..."); \} App.java X Location.java Vehicle.java Miniproject.java Location.java Vehicle.java uverride public void start(Stage stage) \{ var javaVersion = systemInfo.javaVersion(); var javafxVersion = SystemInfo.javafxVersion(); Scanner s= new Scanner(source: System.in); //Start Scene Creation AnchorPane root = new AnchorPane (); Scene scene = new Scene (parent: root, d: 800,d1:600); AnchorPane addPane = new AnchorPane (); Scene addScene = new Scene (parent: addPane, d: 640, di: 480); ListView locationsLV = new ListView (); locationsLV.getItems () .add (new Location (name: "Cleveland", w: 0, Y: 0,Gas_Station:true))); locationsLV.getItems () .add (new Location (name: "North Pole", w: 500,y:-100,6as_station:true)) ; locationsLV.getItems () .add (new Location (name: "Campbell Hill", w: -50,y:-50,6as_Station:false)) ; locationsLV.getItems () .add (new Location (name: "Tokyo", w: -100,7: 1000,6as_Station:true)); locationsLV.getItems () .add (new Location (name: "Chicago", w: -200,y: 75,6as_Station:true)) ; locationsLV.getItems () .add (new Location (name: "Erie PA", w: 150, y: 0,6as_station:true)); locationsLV.getItems () .add (new Location (name: "Allegheny Nation Forrest", "16 300,y:-75,Gas_Station:false)); //End Scene Creation //Start scene Setup //Create and setup controls Label messageLbl = new Label(string: "Hello, I am your AI navigater, you can call me 'Navi for short."); Label nameLbl = new Label (string: "Please create your vehicle"); Label mfcLbl = new Label(string: "What is your vehicle"s Maximum Fuel Capacity: "); Label mpgLbl = new Label (string: "What is your vehicle's Miles Per Gallon: "); Label badInput = new Label (); TextField mfctF = new TextField () ; TextField mpgTF = new TextField (); Button btn = new Button(string: "Create Vehicle"); btn.setonAction (actionEvent \{ messageLbl.setText (string: "Vehicle created."); Vehicle vehicle = new Vehicle ((Location) locationsLV.getItems (), mfc:mfcTF,cf: mfcTF, mpg:mpgTF); stage.setScene (scene: addScene); ) ; //Set AnchorPane positions for controls AnchorPane.setTopAnchor (node: messageLbl, d:20.0); AnchorPane.setLeftAnchor (node: messageLbl, d:20.0); AnchorPane.setTopAnchor (node: nameLbl, d: 60.0) ; AnchorPane.setLeftAnchor (node: nameLbl, d: 20.0); AnchorPane.setTopAnchor (node: mfcLbl, d: 120.0); AnchorPane.setLeftAnchor (node:mfcLbl, d: 20.0); AnchorPane.setTopAnchor (node: mfcTF, d: 140.0); AnchorPane.setLeftAnchor (node:mfcTF, d:20.0); AnchorPane.setTopAnchor (node: mpgLbl, d: 180.0); AnchorPane.setLeftAnchor (node: mpgLbl, d: 20.0); AnchorPane.setTopAnchor (node: mpgTF, d: 200.0); AnchorPane.setLeftAnchor (node:mpgTF, d:20.0); AnchorPane.setBottomAnchor (node:btn, d: 20.0); AnchorPane.setRightAnchor (node:btn, d: 20.0)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

2. Avoid basing most of a report-card grade on one test.

Answered: 1 week ago