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

Written by JJ Shepherd import java applet. //Needed to create the window import

ID: 3807812 • Letter: W

Question

Written by JJ Shepherd import java applet. //Needed to create the window import java awt. //Needed for drawing import java util public class Drawinguines extends Applet(//when it extends applet it creates a window and calls certain methods private Image display; //Used as the flat image private Graphics drawingArea; //Used to draw item in the inage .This is called by the parent Applet, as its an overridden method, and it initializes all of the instance variables. Think of this as a variation of a constructor, but called by another, hidden piece of code public void init() //get the height and width from the Applet int height getsize().height; int width getsize() width //creates an image using the height and width in the applet display create Image (width, height); //sets up the drawing area for the image above to be drawn on drawing Area display get Graphics() This draws the lines drawl ines (drawingArea) This is also called by the applet as it is an overridden method. public void paint (Graphics g) g.drawImage (display,0,0,null); This Draws line

Explanation / Answer

// Interface Line
public interface Line{
   public double getYpoint(double x);
  
}

// Class SlopedLine

Class SlopedLine implements Line
{
   private double slope;
  
   public SlopedLine(){
       slope=0.0;
   }
   public SlopedLine(double s){
       slope=s;
   }
   public double getSlope(){
       return slope;
   }

   public void setSlope( double slp ){  
       slope = slp;
   }
   public double getYpoint(double x){
       return slope*x;
   }
  
}

// Class ExponentialLine

Class ExponentialLine implements Line
{
   private double exponent;
   public ExponentialLine(){
       exponent=0.0;
   }
   public ExponentialLine(double exp){
       exponent=exp;
   }
  
   public void setExponent(double exp){
       exponent=exp;
      
   }
   public double getExponent(){
       return exponent;
   }
  
   public double getYpoint(double x){
       return x^exponent;
   }
  
}

// Class SineLine

Class SineLine implements Line
{
   private double amplitude;
   private double frequency;
  
   public SineLine(){
       amplitude=0.0;
       frequency=0.0;
   }
   public SineLine(double amp, double fre){
       amplitude=amp;
       frequency=fre;
   }
  
   public void setAmplitude(double amp){
       amplitude=amp;
      
   }
   public double getAmplitude(){
       return amplitude;
   }
  
   public void setFrequency(double fre){
       frequency=fre;
   }
   public double getFrequency(){
       return frequency;
   }
   public double getYpoint(double x){
       return mod(x,mod(frequency,height);
   }
  
  
}

//Class StaircaseLine

Class StaircaseLine implements Line
{
   private double width;
   private double height;
  
   public StaircaseLine(){
       width=0.0;
       height=0.0;
   }
   public StaircaseLine(double w, double h){
       width=w;
       height=h;
   }
  
   public void setWidth(double w){
       width=w;
      
   }
   public double getWidth(){
       return width;
   }
  
   public void setHeight(double h){
       height=h;
   }
   public double getHeight(){
       return height;
   }
   public double getYpoint(double x){
       int tmp = height/width; //integer division
       return (tmp*height);
   }
  
  
}