Question

In: Computer Science

class Airplane – highlights -- modelID : String -planeType: String //”propeller” “jet” --fuelOnBoard : int --fuelCapacity:...

class Airplane – highlights

-- modelID : String

-planeType: String //”propeller” “jet”

--fuelOnBoard : int

--fuelCapacity: int //gallons

…………...

Assume getters and setters, toString(), constructor with parameters

and constructor

……………

Write lambdas using a standard functional interface to:

a) Given a plane object and “propeller” or “jet” as an input, determine if the given plane matched the given type

b) Output the plane description and “plane needs fuel” if fuel on board is less than 80% of fuel capacity

c) Adjust the fuel by a specified number of gallons and write an example for each showing the usage, using an Airplane instance plane1

Please use Java, don't use other coding languages to solve it. Thank you

Solutions

Expert Solution

Explanation:I have written Airplane class, all the three functional interfaces and an AirplaneTester class to test the interfaces.I have also shown the example for each in the output, please find the image attached with the answer.Please upvote if you liked my answer and comment if you need any modification or explanation

//code

//Airplane class

public class Airplane {
   private String modelID;

   private String planeType;

   private int fuelOnBoard;

   private int fuelCapacity;

   public Airplane(String modelID, String planeType, int fuelOnBoard,
           int fuelCapacity) {
       super();
       this.modelID = modelID;
       this.planeType = planeType;
       this.fuelOnBoard = fuelOnBoard;
       this.fuelCapacity = fuelCapacity;
   }

   public String getModelID() {
       return modelID;
   }

   public void setModelID(String modelID) {
       this.modelID = modelID;
   }

   public String getPlaneType() {
       return planeType;
   }

   public void setPlaneType(String planeType) {
       this.planeType = planeType;
   }

   public int getFuelOnBoard() {
       return fuelOnBoard;
   }

   public void setFuelOnBoard(int fuelOnBoard) {
       this.fuelOnBoard = fuelOnBoard;
   }

   public int getFuelCapacity() {
       return fuelCapacity;
   }

   public void setFuelCapacity(int fuelCapacity) {
       this.fuelCapacity = fuelCapacity;
   }

   @Override
   public String toString() {
       return "Airplane [modelID=" + modelID + ", planeType=" + planeType
               + ", fuelOnBoard=" + fuelOnBoard + ", fuelCapacity="
               + fuelCapacity + "]";
   }

}

//MatchTypeInterface

@FunctionalInterface
public interface MatchTypeInterface {

   public boolean matches(Airplane plane, String type);

}

//DescriptionInterface

@FunctionalInterface
public interface DescriptionInterface {
   public void display(Airplane plane);
}

//AdjustFuelInterface

@FunctionalInterface
public interface AdjustFuelInterface {
   public void adjustFuel(Airplane plane, int noOfGallons);
}

//AirplaneTest class

public class AirplaneTest {

   public static void main(String[] args) {

       MatchTypeInterface matchInterface = (plane, type) -> {
           return plane.getPlaneType() == type;
       };
       Airplane plane1 = new Airplane("A123", "propeller", 1400, 2000);
       String planeType = "propeller";
       System.out.println(matchInterface.matches(plane1, planeType));
       planeType = "jet";
       System.out.println(matchInterface.matches(plane1, planeType));
       System.out.println();
       DescriptionInterface descriptionInterface = (plane) -> {
           System.out.println("Description:");
           System.out.println(plane.toString());
           if (plane.getFuelOnBoard() < (0.8 * plane.getFuelCapacity())) {
               System.out.println("plane needs fuel");
           }
       };
       descriptionInterface.display(plane1);
       System.out.println();
       AdjustFuelInterface adjustFuelInterface = (plane, noOfGallons) -> {
           System.out.println("Before adjustment fuel onboard: "
                   + plane.getFuelOnBoard());
           plane.setFuelOnBoard(plane.getFuelOnBoard() + noOfGallons);
           System.out.println(
                   "After adjustment fuel onboard: " + plane.getFuelOnBoard());
       };
       adjustFuelInterface.adjustFuel(plane1, 4);

   }

}

Output:


Related Solutions

Consider the following class: class Person {         String name;         int age;        ...
Consider the following class: class Person {         String name;         int age;         Person(String name, int age){                this.name = name;                this.age = age;         } } Write a java program with two classes “Teacher” and “Student” that inherit the above class “Person”. Each class has three components: extra variable, constructor, and a method to print the student or the teacher info. The output may look like the following (Hint: you may need to use “super”...
Given this class: class Issue { public:                 string problem; int howBad; void setProblem(string problem); };...
Given this class: class Issue { public:                 string problem; int howBad; void setProblem(string problem); }; And this code in main: vector<Issue> tickets; Issue issu; a) tickets.push_back(-99); State whether this code is valid, if not, state the reason b) Properly implement the setProblem() method as it would be outside of the class. You MUST name the parameter problem as shown in the prototype like: (string problem) c) Write code that will output the problem attribute for every element in the...
class ArrayStringStack { String stack[]; int top; public arrayStringStack(int size) { stack = new String[size]; top...
class ArrayStringStack { String stack[]; int top; public arrayStringStack(int size) { stack = new String[size]; top = -1; } //Assume that your answers to 3.1-3.3 will be inserted here, ex: // full() would be here //empty() would be here... //push() //pop() //displayStack() } 1. Write two boolean methods, full( ) and empty( ). 2. Write two methods, push( ) and pop( ). Note: parameters may be expected for push and/or pop. 3. Write the method displayStack( ) that prints the...
1. The angle of an airplane propeller makes with the horizontal as a function of time...
1. The angle of an airplane propeller makes with the horizontal as a function of time is given by θ=(125rad/s)t+(42.5rad/s^2)t^2. estimate the instantaneous angular velocity at t=0.00s by calculating the average angular velocity from t=0.00s to t=0.010s A. Estimate the angular speed at t = 0 by calculating the average angular speed between ti = 0 and tf = 0s. B. Estimate the angular speed at t = 1.00 by calculating the average angular speed between ti = 1.00 and...
Consider the following java class: class Student {    private int student_Number;    private String student_Name;    public Student(int...
Consider the following java class: class Student {    private int student_Number;    private String student_Name;    public Student(int stNo,String name) {         student_Number=stNo;         student_Name=name;      }     public String getName() {       return student_Name;     }      public int getNumber() {       return student_Number;      }     public void setName(String st_name) {       student_Name = st_name;     } } Write a Tester class named StudentTester which contains the following instruction: Use the contractor to create a student object where student_Number =12567, student_Name = “Ali”. Use the setName method to change the name of...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string • speed : float Create a FigherPlane class that inherits from the Airplane class and adds the following attributes: • numberOfMissiles : short
public class Book{     public String title;     public String author;     public int year;    ...
public class Book{     public String title;     public String author;     public int year;     public String publisher;     public double cost;            public Book(String title,String author,int year,String publisher,double cost){        this.title=title;         this.author=author;         this.year=year;         this.publisher=publisher;         this.cost=cost;     }     public String getTitle(){         return title;     }         public String getAuthor(){         return author;     }     public int getYear(){         return year;     }     public String getPublisher(){         return publisher;...
public class Classroom { // fields private String roomNumber; private String buildingName; private int capacity; /**...
public class Classroom { // fields private String roomNumber; private String buildingName; private int capacity; /** * Constructor for objects of class Classroom */ public Classroom() { this.capacity = 0; }    /** * Constructor for objects of class Classroom * * @param rN the room number * @param bN the building name * @param c the room capacity */ public Classroom(String rN, String bN, int c) { setRoomNumber(rN); setBuildingName(bN); setCapacity(c); }    /** * Mutator method (setter) for room...
Here is class Dog -String name; -int age -String breed; -boolean adopted; //false if available …………………...
Here is class Dog -String name; -int age -String breed; -boolean adopted; //false if available ………………… +constructor, getters, setters, toString() Write a lambda expression showAdoptable using a standard functional interface that will display the dog’s name age and breed if adopted is false. Help please!!
int bintodec(string); // converts a binary number (represented as a STRING) to decimal int hextodec(string); //...
int bintodec(string); // converts a binary number (represented as a STRING) to decimal int hextodec(string); // converts a hexadecimal number (represented as a STRING) to decimal string dectobin(int); // converts a decimal number to binary (represted as a STRING) string dectohex(int); // converts a decimal number to hexadecimal (represted as a STRING) //the addbin and addhex functions work on UNsigned numbers string addbin(string, string); // adds two binary numbers together (represented as STRINGS) string addhex(string, string); // adds two hexadecimal...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT