Question

In: Computer Science

JAVA question here, and thank you. I need ot update the following classes an fixme's on...

JAVA question here, and thank you. I need ot update the following classes an fixme's on this.canvas = null etc.

Thanks!

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import edu.luc.etl.cs313.android.shapes.model.*;

/**
 * A Visitor for drawing a shape to an Android canvas.
 */
public class Draw implements Visitor<Void> {

   // TODO entirely your job (except onCircle)

   private final Canvas canvas;

   private final Paint paint;

   public Draw(final Canvas canvas, final Paint paint) {
      this.canvas = null; // FIXME
      this.paint = null; // FIXME
      paint.setStyle(Style.STROKE);
   }

   @Override
   public Void onCircle(final Circle c) {
      canvas.drawCircle(0, 0, c.getRadius(), paint);
      return null;
   }

   @Override
   public Void onStrokeColor(final StrokeColor c) {

      return null;
   }

   @Override
   public Void onFill(final Fill f) {

      return null;
   }

   @Override
   public Void onGroup(final Group g) {

      return null;
   }

   @Override
   public Void onLocation(final Location l) {

      return null;
   }

   @Override
   public Void onRectangle(final Rectangle r) {

      return null;
   }

   @Override
   public Void onOutline(Outline o) {

      return null;
   }

   @Override
   public Void onPolygon(final Polygon s) {

      final float[] pts = null;

      canvas.drawLines(pts, paint);
      return null;
   }
}

Solutions

Expert Solution

// Source Code:

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import edu.luc.etl.cs313.android.shapes.model.*;
import java.util.Iterator;
import java.util.List;


/**
 * A Visitor for drawing a shape to an Android canvas.
 */
public class Draw implements Visitor<Void> {

    private final Canvas canvas;

    private final Paint paint;

    public Draw(final Canvas canvas, final Paint paint) {
        this.canvas = canvas;
        this.paint = paint;
        paint.setStyle(Style.STROKE);
    }

    @Override
    public Void onCircle(final Circle c) {
        canvas.drawCircle(0, 0, c.getRadius(), paint);
        return null;
    }

    @Override
    public Void onStrokeColor(final StrokeColor c) {
        final int x = paint.getColor();
        paint.setColor(c.getColor());
        c.getShape().accept(this);
        paint.setColor(x);
        return null;
    }

    @Override
    public Void onFill(final Fill f) {
        final Style a = paint.getStyle();
        paint.setStyle(Style.FILL_AND_STROKE);
        f.getShape().accept(this);
        paint.setStyle(a);
        return null;
    }

    @Override
    public Void onGroup(final Group g) {
        final Iterator<? extends Shape > shape = g.getShapes().iterator();
        while (shape.hasNext()) {
            shape.next().accept(this);
        }
        return null;
    }

    @Override
    public Void onLocation(final Location l) {
        canvas.translate(l.getX(), l.getY());
        l.getShape().accept(this);
        canvas.translate(-l.getX(), -l.getY());
        return null;
    }

    @Override
    public Void onRectangle(final Rectangle r) {
        canvas.drawRect(0, 0, r.getWidth(), r.getHeight(), paint);
        return null;
    }

    @Override
    public Void onOutline(Outline o) {
        final Style before = paint.getStyle();
        paint.setStyle(Style.STROKE);
        o.getShape().accept(this);
        paint.setStyle(before);
        return null;
    }

    @Override
    public Void onPolygon(final Polygon s) {
        List<? extends Point> points = s.getPoints();
        final float[] pts =
                {
                        points.get(0).getX(), points.get(0).getY(),
                        points.get(1).getX(), points.get(1).getY(),
                        points.get(1).getX(), points.get(1).getY(),
                        points.get(2).getX(), points.get(2).getY(),
                        points.get(2).getX(), points.get(2).getY(),
                        points.get(3).getX(), points.get(3).getY(),
                        points.get(0).getX(), points.get(0).getY(),
                };
        canvas.drawLines(pts, paint);
        return null;
    }
}

Related Solutions

I need to update this program to follow the these requirements please and thank you :...
I need to update this program to follow the these requirements please and thank you : Do not use packages Every class but the main routine class must have a toString method . The toString method for Quadrilateral should display its fields: 4 Points. All instance variables should be declared explicitly private . Area incorrect : enter points no: 1 1 3 enter points no: 2 6 3 enter points no: 3 0 0 enter points no: 4 5 0...
Java question: I need to fix a point class (code below) Thank you! /** * A...
Java question: I need to fix a point class (code below) Thank you! /** * A point, implemented as a location without a shape. */ public class Point extends Location { // TODO your job // HINT: use a circle with radius 0 as the shape! public Point(final int x, final int y) { super(-1, -1, null); assert x >= 0; assert y >= 0; } }
I only need to update this JAVA program to be able to : 1 ) Exit...
I only need to update this JAVA program to be able to : 1 ) Exit cleanly after creating the chart 2 ) change the pie chart to a perfect circle rather than an oval 3 ) provide a separate class driver import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.util.Scanner; import javax.swing.JComponent; import javax.swing.JFrame; // class to store the value and color mapping of the // pie segment(slices) class Segment { double value; Color color; // constructor public...
I think I have this figured out, but need a double check... Thank you Here is...
I think I have this figured out, but need a double check... Thank you Here is the question: Regional distributors are currently using continuous review inventory policy. Compute and describe their inventory management policy and associated cost. Ignore inbound and outbound transportation cost. Provide answers and calculations for order quantity, demand during lead time, safety stock, average inventory level, inventory holding cost per week, ordering cost per week, and total cost per week. The service level is 90% and the...
I need a Java application with a GUI that includes the following requirements: Three classes minimum...
I need a Java application with a GUI that includes the following requirements: Three classes minimum At least one class must use inheritance At least one class must be abstract Utilization of “get set” method. (get; set; =  is related to how variables are passed between different classes. The get method is used to obtain or retrieve a particular variable value from a class. A set value is used to store the variables. The whole point of the get and set...
I need this Java code translated into C Code. Thank you. //Logical is the main public...
I need this Java code translated into C Code. Thank you. //Logical is the main public class public class Logical { public static void main(String args[]) { char [][] table= {{'F','F','F'},{'F','F','T'},{'F','T','F'},{'F','T','T'},{'T','F','F'},{'T','F','T'},{'T','T','F'},{'T','T','T'}}; // table contains total combinations of p,q,& r int totalTrue, totalFalse, proposition;    //proposition 1: proposition=1; start(proposition); totalTrue=0; totalFalse=0; for(int i=0;i<8;i++) {    { char o= conjuctive(implecation(negation(table[i][0]),table[i][1]),implecation(table[i][2],table[i][0])); System.out.println(" "+table[i][0]+" "+table[i][1]+" "+table[i][2]+" "+o); if(o=='T') totalTrue++; else totalFalse++;    } } finalOutput(totalTrue,totalFalse,proposition); System.out.println(" "); System.out.println(" ");    //proposition 2: proposition=2; start(proposition);...
Question: Can I get the code in Java for this assignment to compare? Please and thank you....
Question: Can I get the code in Java for this assignment to compare? Please and thank you. Can I get the code in Java for this assignment to compare? Please and thank you. Description Write a Java program to read data from a text file (file name given on command line), process the text file by performing the following: Print the total number of words in the file. Print the total number of unique words (case sensitive) in the file. Print...
I need to update this java program to take input about each employee from a file...
I need to update this java program to take input about each employee from a file and write their information and salary/pay information to a file. use input file payroll.txt Kevin Yang 60 20 Trey Adams 30 15 Rick Johnson 45 10 Cynthia Wheeler 55 11.50 Sarah Davis 24 10 Muhammad Rabish 66 12 Dale Allen 11 18 Andrew Jimenez 80 15 import java.util.Scanner; public class SalaryCalcLoop { double Rpay = 0, Opay = 0; void calPay(double hours, double rate)...
I need to update this java program to take input about each employee from a file...
I need to update this java program to take input about each employee from a file and write their information and salary/pay information to a file. use input file payroll.txt import java.util.Scanner; public class SalaryCalcLoop { double Rpay = 0, Opay = 0; void calPay(double hours, double rate) { if (hours <= 40) { Rpay = hours * rate; Opay = 0; } else { double Rhr, Ohr; Rhr = 40; Ohr = hours - Rhr; Rpay = Rhr *...
Here is the question. I understand what the answer is but need to know how you...
Here is the question. I understand what the answer is but need to know how you calculate the PV at 12% in year 5 to equal .567. You have worked in XYZ Corporation for the last five years and have a more optimistic view of the firm's future FCFs. In your personal/professional opinion, XYZ could generate $4 million FCF next year, $4.5 million in year two, $5 million in year three, $5.5 million in year four, $6 million in year...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT