Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use the following to given codes GraphicsFrame class & Drawable interface

ID: 665497 • Letter: P

Question

Please use the following to given codes GraphicsFrame class & Drawable interface. Please do not modify the other classes.

In this practice lab we are going to make use of the GraphicsFrame class and the Drawable interface. Your mission is to create the class Airplane. Each Airplane object should store the following information (fields):

manufacturer
modelNumber
maximumSpeed // in knots
maximumFuel // in gallons
grossWeight // in lbs
emptyWeight

Each airplane object should have the following behaviors (methods):

public float usefulLoad() // this is the grossWeight - emptyWeight
public float usefulLoadWithFuel( in gallons ) // this is the useful load - gallons x 6. The programmer user will pass in the number of gallons on board.

public void draw( Graphics g ) // this method will make a line drawing of an airplane. You don't have to get fancy. Do use drawString() to display the Airplanes information.

You will also need a constructor to initialize the fields.

Make sure you look at the example of GraphicsFrame. You will need to put the GraphicsFrame, Drawable, Airplane, and the test driver all in one folder. The files need to 'see' each other. You can just add on the the test driver for the example.

Some starter code for the Airplane class:

public class Airplane implements Drawable

{

// fields

// constructor or constructors

// general methods

}

* If the drawList is full, the console message "Draw list full" * is displayed. * * @param d an object that implements the Drawable interface. */ public void add( Drawable d ) { if (endOfList + 1 < LIST_MAX) { endOfList++; drawList[endOfList] = d; } else { System.out.println("Draw list full"); } drawPan.repaint(); } /** * Re-draws the the drawList in the window. * Forces a repaint of the GraphicsFrame window. * Each object on the draw list is re-drawn. */ public void redraw() { drawPan.repaint(); } /** * Sets the background color of the window. * The c argument must be of type Color. *

* There are several default color objects. * The defalut color for the window is Color.WHITE * * @param c a type Color object. * @see Color */ public void setBackgroundColor( Color c ) { backgroundColor = c; } // private inner class from which the drawing area is created private class DrawPanel extends JPanel { public void paintComponent( Graphics g ) { super.paintComponent( g ); setBackground( backgroundColor ); for( int i=0; i <= endOfList; i++ ) { drawList[ i ].draw( g ); } } }// end of DrawPanel }

_____________________________________________________

OTHER CODES THAT MAY NOIT BE NEEDED

Drawable Code

User code should never call draw directly. draw will be * called by automagically by a GraphicsFrame object. */ public void draw( Graphics g ); }

__________________________________________________________________

DrawSomeStuff

________________________________________________________

DrawSomeStuffTest

Explanation / Answer

import javax.swing.*;
import java.awt.*;

class Airplane implements Drawable{
   String modelNumber;
   float maximumSpeed;
   float maximumFuel;
   float grossWeight;
   float emptyWeight;
   public Airplane(String num,float speed,float fuel,float weight.float empty){
       modelNumber = num;
       maximumSpeed = speed;
       maximumFuel = fuel;
       grossWeight = weight;
       emptyWeight = empty;
   }
   public float usefulLoad(){
       return grossWeight - emptyWeight;
   }
   public float usefulLoadWithFuel(int g){
       return usefulLoad() - 6*g;
   }
   public void draw(Graphics g){
       int fontSize = 20;
       g.setFont(new Font("TimesRoman", Font.PLAIN, 20));
       g.setColor(Color.red);
       g.drawString("Model Number is : "+modelNumber,10,10);
       g.drawString("Maximum Speed is : "+maximumSpeed,10,60);
       g.drawString("Maximum Fuel is : "+maximumFuel,10,110);
       g.drawString("Gross Weight is : "+grossWeight,10,160);
       g.drawString("Empty weight is : "+emptyWeight,10,210);
       g.drawString("usefulLoad is : "+usefulLoad(),10,260);
       g.drawString("usefulLoadWithFuel is : "+usefulLoadWithFuel(),10,310);
   }
}