Question: This is a question for my assignment, please respond with the correct code as soon as you can. To be done on Java. Will upvote

This is a question for my assignment, please respond with the correct code as soon as you can. To be done on Java. Will upvote definitely, thanks!

Part A

/** Class to get surface area and volume of a soda can. */ public class SodaCan implements Measurable { private double height; private double radius;

/** Initializes a can with given height and radius. @param height the height @param radius the radius */ public SodaCan(double height, double radius) { this.height = height; this.radius = radius; }

/** Calculates the surface area of the soda can. @return the surface area of the soda can */ public double getSurfaceArea() { return 2 * Math.PI * radius * (radius + height); }

/** Calculates the volume of the soda can. @return the volume of the soda can */ public double getVolume() { return Math.PI * radius * radius * height; }

/** Returns the area of the soda can. @return the area of the soda can */ //-----------Start below here. To do: approximate lines of code = 2 // write a method that correctly implements the Measurable interface // The method should return the surface area of the sodaCan object //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. }

Part B

/** A class to calculate the area of several SodaCans */ public class SodaCanTester { /** Calculates the average area in an array list of SodaCans @param SodaCanArray the SodaCans @return the average area of SodaCanArray */ private static double averageArea(Measurable[] sodaCanArray) { //-----------Start below here. To do: approximate lines of code = 4 // get the measure of area from all sodaCan objects in the array, add them up and // compute the average. return the average //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. }

public static void main(String[] args) { SodaCan[] sodaCans = new SodaCan[4]; sodaCans[0] = new SodaCan(2, 3); sodaCans[1] = new SodaCan(3, 3); sodaCans[2] = new SodaCan(5, 7); sodaCans[3] = new SodaCan(1, 1); System.out.printf("The average area is: %10.2f", averageArea(sodaCans)); System.out.println(" Expected: The average area is: 186.92"); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!