Modify the code to add another attribute and a method that fits (is consistent with) the object the class is modeling, or suggest a different
Modify the code to add another attribute and a method that fits (is consistent with) the object the class is modeling, or suggest a different version of the code. Write the main method to demonstrate the correct functionality of the additions.
public class Airplane { boolean flying; int altitude; int speed; boolean armed; boolean fueled; String name;
public Airplane(String name, boolean flying, int altitude, int speed, boolean armed, boolean fueled) { this.flying = flying; this.altitude = altitude; this.speed = speed; this.armed = armed; this.fueled = fueled; this.name = name; }
public boolean goingFast() { if (this.speed >= 700) { return true;} return false; }
public boolean flyingHigh() { if (this.altitude >= 10000) { return true;} return false; } public boolean combatReady() { if (this.armed == true && this.fueled == true) { return true; } return false; } } ==========================
import java.util.*; public class Fleet {
public static void main(String[] args) { Scanner sc = new Scanner(System.in); String name = "Random"; int altitude = 0; int speed = 0; boolean fueled = true; boolean flying = true; boolean armed = true; Airplane Aircraft = new Airplane( name, flying, altitude, speed, armed, fueled); // random objects i created to get a feel for what i was doing /*Airplane A10 = new Airplane(true, 8300, 320, true, true);
Airplane F15 = new Airplane(false, 0, 0, true, false); Airplane F16 = new Airplane(true, 15000, 790, true, true); Airplane C17 = new Airplane(true, 25000, 600, false, true); Airplane C130 = new Airplane(true, 20000, 450, false, true);*/ System.out.println("What aircaft would you like to set up"); name = sc.next(); System.out.println("Is the " +name+ " flying? and is it fueled? enter [true] for yes and [false] for no."); flying = sc.nextBoolean(); fueled = sc.nextBoolean(); System.out.println("Is the Aircraft Armed?"); armed = sc.nextBoolean(); System.out.println(" How high and how fast do you want the " +name+ " to fly?"); altitude = sc.nextInt(); speed = sc.nextInt();
Aircraft = new Airplane(name, flying, altitude, speed, armed, fueled); System.out.println("The " + name + " will proceed to "+ Aircraft.altitude +" feet at and maintain speed of " + Aircraft.speed + "mph"); System.out.println(name + " Combat Ready Status: " + Aircraft.combatReady()); }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres a modified version of the Airplane class with an additional attribute and method that fit the object the class is modeling java public class Air...See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started