SlideShare una empresa de Scribd logo
1 de 4
Descargar para leer sin conexión
public interface Measurable
{
double getMeasure();
/**
Computes the smallest of the measures of the given objects.
@param objects an array of Measurable objects
@return the object with the smallest measure, null if array is empty
*/
static Measurable smallest(Measurable[] objects)
{
if (objects.length == 0)
{
return null;
}
Measurable min = objects[0];
for (Measurable obj : objects)
{
if (obj.getMeasure() < min.getMeasure())
{
min = obj;
}
}
return min;
}
/**
Computes the largest of the measures of the given objects.
@param objects an array of Measurable objects
@return the object with the largest measure, null if array is empty
*/
static Measurable largest(Measurable[] objects)
{
if (objects.length == 0)
{
return null;
}
Measurable max = objects[0];
for (Measurable obj : objects)
{
if (obj.getMeasure() > max.getMeasure())
{
max = obj;
}
}
return max;
}
}
*************************************************************************************************************
/**
Class to get surface area and volume of a soda can. You are to
write the class definition and implement the getMeasure method.
*/
//-----------Start below here. To do: approximate lines of code = 1
// Define the class SodaCan and have it implement Measurable
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the
todo regions.
{
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.
}
****************************************************************************************************************
******************
/**
A class to calculate the area of several SodaCans. You are to complete the
following:
- Complete the method totalMeasure which calculates the total measure over all the Measurable
items in a given array
*/
public class SodaCanTester
{
/**
Calculates the total measure over all the given Measurable items
@param items the items
@return the total measure of the items
*/
private static double totalMeasure(Measurable[] items)
{
//-----------Start below here. To do: approximate lines of code = 4
// get the measure from all objects in the array, add them up and
// return the total
//-----------------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.println("--- TEST 1: Calculate the total in a standard case");
System.out.printf("RESULT: %.2fn", totalMeasure(sodaCans));
System.out.println("EXPECTED: 747.70");
System.out.println("n--- TEST 2: Calculate the total for empty array");
System.out.printf("RESULT: %.2fn", totalMeasure(new APerson[0]));
System.out.println("EXPECTED: 0.00");
}
}

Más contenido relacionado

Similar a public interface Measurable double getMeasure Com.pdf

StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docxstudent start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
hanneloremccaffery
 
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docxAssg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
festockton
 
Passing arguments by-Value and using return types.#includeiost.pdf
Passing arguments by-Value and using return types.#includeiost.pdfPassing arguments by-Value and using return types.#includeiost.pdf
Passing arguments by-Value and using return types.#includeiost.pdf
jillisacebi75827
 
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdfimport java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
aquacareser
 
Describe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdfDescribe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdf
arihantstoneart
 
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxAvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
rock73
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
fantasiatheoutofthef
 
@author Derek Harter @cwid 123 45 678 @class .docx
@author Derek Harter  @cwid   123 45 678  @class  .docx@author Derek Harter  @cwid   123 45 678  @class  .docx
@author Derek Harter @cwid 123 45 678 @class .docx
adkinspaige22
 
template-typename T- class Array { public- ---------------------------.pdf
template-typename T- class Array { public- ---------------------------.pdftemplate-typename T- class Array { public- ---------------------------.pdf
template-typename T- class Array { public- ---------------------------.pdf
ashokadyes
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
seoagam1
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
MAYANKBANSAL1981
 
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdfCounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
deepua8
 
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docxProgram 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
wkyra78
 

Similar a public interface Measurable double getMeasure Com.pdf (20)

StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docxstudent start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
 
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docxAssg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
 
Passing arguments by-Value and using return types.#includeiost.pdf
Passing arguments by-Value and using return types.#includeiost.pdfPassing arguments by-Value and using return types.#includeiost.pdf
Passing arguments by-Value and using return types.#includeiost.pdf
 
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdfimport java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
 
Recursion to iteration automation.
Recursion to iteration automation.Recursion to iteration automation.
Recursion to iteration automation.
 
Describe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdfDescribe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdf
 
Microsoft word java
Microsoft word   javaMicrosoft word   java
Microsoft word java
 
Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
 
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxAvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
 
@author Derek Harter @cwid 123 45 678 @class .docx
@author Derek Harter  @cwid   123 45 678  @class  .docx@author Derek Harter  @cwid   123 45 678  @class  .docx
@author Derek Harter @cwid 123 45 678 @class .docx
 
Algorithms devised for a google interview
Algorithms devised for a google interviewAlgorithms devised for a google interview
Algorithms devised for a google interview
 
template-typename T- class Array { public- ---------------------------.pdf
template-typename T- class Array { public- ---------------------------.pdftemplate-typename T- class Array { public- ---------------------------.pdf
template-typename T- class Array { public- ---------------------------.pdf
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
 
Write a class called Fraction with the two instance variables denomin.docx
 Write a class called Fraction with the two instance variables denomin.docx Write a class called Fraction with the two instance variables denomin.docx
Write a class called Fraction with the two instance variables denomin.docx
 
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdfCounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
 
Multithreaded sockets c++11
Multithreaded sockets c++11Multithreaded sockets c++11
Multithreaded sockets c++11
 
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docxProgram 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
 

Más de addtechglobalmarketi

pular Madde 5 Aadaki durumda orijinal kaynak materyal b.pdf
pular  Madde 5  Aadaki durumda orijinal kaynak materyal b.pdfpular  Madde 5  Aadaki durumda orijinal kaynak materyal b.pdf
pular Madde 5 Aadaki durumda orijinal kaynak materyal b.pdf
addtechglobalmarketi
 
public class Monster protected String clanAffiliation pro.pdf
public class Monster  protected String clanAffiliation pro.pdfpublic class Monster  protected String clanAffiliation pro.pdf
public class Monster protected String clanAffiliation pro.pdf
addtechglobalmarketi
 
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdfPrpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
addtechglobalmarketi
 

Más de addtechglobalmarketi (20)

Pundits have stated that the recent tax cut mainly benefits .pdf
Pundits have stated that the recent tax cut mainly benefits .pdfPundits have stated that the recent tax cut mainly benefits .pdf
Pundits have stated that the recent tax cut mainly benefits .pdf
 
Pt is 76 year old with pneumonia and malnutrition Patient i.pdf
Pt is 76 year old with pneumonia and malnutrition Patient i.pdfPt is 76 year old with pneumonia and malnutrition Patient i.pdf
Pt is 76 year old with pneumonia and malnutrition Patient i.pdf
 
Punto 13 Punto 13 Mindy se adapt rpidamente a su puesto en.pdf
Punto 13 Punto 13 Mindy se adapt rpidamente a su puesto en.pdfPunto 13 Punto 13 Mindy se adapt rpidamente a su puesto en.pdf
Punto 13 Punto 13 Mindy se adapt rpidamente a su puesto en.pdf
 
Pulse can be palpated on a number of arteries around the bod.pdf
Pulse can be palpated on a number of arteries around the bod.pdfPulse can be palpated on a number of arteries around the bod.pdf
Pulse can be palpated on a number of arteries around the bod.pdf
 
Puntaje Puntaje.pdf
Puntaje            Puntaje.pdfPuntaje            Puntaje.pdf
Puntaje Puntaje.pdf
 
Punnett Squares se puede extender ms all de un simple cruc.pdf
Punnett Squares se puede extender ms all de un simple cruc.pdfPunnett Squares se puede extender ms all de un simple cruc.pdf
Punnett Squares se puede extender ms all de un simple cruc.pdf
 
pular Madde 5 Aadaki durumda orijinal kaynak materyal b.pdf
pular  Madde 5  Aadaki durumda orijinal kaynak materyal b.pdfpular  Madde 5  Aadaki durumda orijinal kaynak materyal b.pdf
pular Madde 5 Aadaki durumda orijinal kaynak materyal b.pdf
 
Puede crear numerosas vistas personalizadas para usar con to.pdf
Puede crear numerosas vistas personalizadas para usar con to.pdfPuede crear numerosas vistas personalizadas para usar con to.pdf
Puede crear numerosas vistas personalizadas para usar con to.pdf
 
publie elass h 1 pahlte clamsia axcends A pablie clann Main .pdf
publie elass h 1 pahlte clamsia axcends A pablie clann Main .pdfpublie elass h 1 pahlte clamsia axcends A pablie clann Main .pdf
publie elass h 1 pahlte clamsia axcends A pablie clann Main .pdf
 
Puede una empresa ser buena en responsabilidad social corpo.pdf
Puede una empresa ser buena en responsabilidad social corpo.pdfPuede una empresa ser buena en responsabilidad social corpo.pdf
Puede una empresa ser buena en responsabilidad social corpo.pdf
 
public class Monster protected String clanAffiliation pro.pdf
public class Monster  protected String clanAffiliation pro.pdfpublic class Monster  protected String clanAffiliation pro.pdf
public class Monster protected String clanAffiliation pro.pdf
 
Provide three evidences with scholar reference that support.pdf
Provide three evidences with scholar  reference that support.pdfProvide three evidences with scholar  reference that support.pdf
Provide three evidences with scholar reference that support.pdf
 
Provincial Government The name of the representative of the .pdf
Provincial Government The name of the representative of the .pdfProvincial Government The name of the representative of the .pdf
Provincial Government The name of the representative of the .pdf
 
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdfPrpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
 
Provide three evidences with reliable reference that suppor.pdf
Provide three evidences with reliable  reference that suppor.pdfProvide three evidences with reliable  reference that suppor.pdf
Provide three evidences with reliable reference that suppor.pdf
 
Provide the Independent variables Dependent variables a.pdf
Provide the Independent variables Dependent variables a.pdfProvide the Independent variables Dependent variables a.pdf
Provide the Independent variables Dependent variables a.pdf
 
Provide your example of a firm or a small business from the .pdf
Provide your example of a firm or a small business from the .pdfProvide your example of a firm or a small business from the .pdf
Provide your example of a firm or a small business from the .pdf
 
Provide the steps for the following In order to install sof.pdf
Provide the steps for the following In order to install sof.pdfProvide the steps for the following In order to install sof.pdf
Provide the steps for the following In order to install sof.pdf
 
Provide land use land cover images and photos using shape.pdf
Provide land use land cover images and photos  using shape.pdfProvide land use land cover images and photos  using shape.pdf
Provide land use land cover images and photos using shape.pdf
 
Provide SQL that creates two database tables Employee and D.pdf
Provide SQL that creates two database tables Employee and D.pdfProvide SQL that creates two database tables Employee and D.pdf
Provide SQL that creates two database tables Employee and D.pdf
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 

Último (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

public interface Measurable double getMeasure Com.pdf

  • 1. public interface Measurable { double getMeasure(); /** Computes the smallest of the measures of the given objects. @param objects an array of Measurable objects @return the object with the smallest measure, null if array is empty */ static Measurable smallest(Measurable[] objects) { if (objects.length == 0) { return null; } Measurable min = objects[0]; for (Measurable obj : objects) { if (obj.getMeasure() < min.getMeasure()) { min = obj; } } return min; } /** Computes the largest of the measures of the given objects. @param objects an array of Measurable objects @return the object with the largest measure, null if array is empty */ static Measurable largest(Measurable[] objects) { if (objects.length == 0) { return null; } Measurable max = objects[0]; for (Measurable obj : objects) { if (obj.getMeasure() > max.getMeasure()) { max = obj; }
  • 2. } return max; } } ************************************************************************************************************* /** Class to get surface area and volume of a soda can. You are to write the class definition and implement the getMeasure method. */ //-----------Start below here. To do: approximate lines of code = 1 // Define the class SodaCan and have it implement Measurable //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. { 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; }
  • 3. /** 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. } **************************************************************************************************************** ****************** /** A class to calculate the area of several SodaCans. You are to complete the following: - Complete the method totalMeasure which calculates the total measure over all the Measurable items in a given array */ public class SodaCanTester { /** Calculates the total measure over all the given Measurable items @param items the items @return the total measure of the items */ private static double totalMeasure(Measurable[] items) { //-----------Start below here. To do: approximate lines of code = 4 // get the measure from all objects in the array, add them up and // return the total //-----------------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.println("--- TEST 1: Calculate the total in a standard case"); System.out.printf("RESULT: %.2fn", totalMeasure(sodaCans));
  • 4. System.out.println("EXPECTED: 747.70"); System.out.println("n--- TEST 2: Calculate the total for empty array"); System.out.printf("RESULT: %.2fn", totalMeasure(new APerson[0])); System.out.println("EXPECTED: 0.00"); } }