Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey guys, I'm having trouble getting my java code to work, I'm getting return 0 when I run my tester, it doesn't look like i

Hey guys, I'm having trouble getting my java code to work, I'm getting return 0 when I run my tester, it doesn't look like i need a tester from the instructions, but I wanna test out my classes: here are the instructions and my code so far:

image text in transcribedimage text in transcribed

Geometry Tester Class:

import java.util.Scanner; public class GeometryTester { public static void main(String[] args) { // TODO Auto-generated method stub Sphere dog = new Sphere(2); double str= dog.getSurfaceArea(); System.out.print(str); } }

Sphere Class:

public class Sphere { private int radii; /** * Constructs a sphere given a radius * @param radius : radius of the sphere * (Precondition: 0>=radius) */ public Sphere(int radius) { radius= radii; } /** * Computes the volume of the sphere * @return the volume of the sphere */ public double getVolume() { double volume = (4*Math.PI*Math.pow(radii, 3))/3; return volume; } /** * Computes the surface area of the sphere * @return the surface area of the sphere */ public double getSurfaceArea() { return 4*Math.PI *radii*radii; } }

Cylinder Class:

public class Cylinder { private int radius; private int height; /** * Constructs a cylinder given the radius and height * @param radii: radius of the cylinder * @param cheight: height of the cylinder * (Preconditon: 0>=radii and 0>= cheight) */ public Cylinder(int radii, int cheight) { radii= radius; cheight = height; } /** * computes the volume of the cylinder * @return the volume of the cylinder */ public double getVolume() { double volume = Math.PI * radius * radius * height; return volume; } /** * computes the surface area of the cylinder * @return the surface area of the cylinder */ public double getSurfaceArea() { double area = 2 * Math.PI* radius * (radius+ height); return area; } }

Cone Class:

public class Cone { private int height; private int radius; /** * Construct a cone with a given radius and height * @param h is the height of the cone * @param r is the radius of the cone * (Precondition: 0>=r and 0>=h) */ public Cone(int h, int r) { r= radius; h= height; } /** * Will compute the volume of the cone * @return the volume of the cone */ public double getVolume() { double volume = (1.0/3.0) * Math.PI*radius*radius*height; return volume; } /** * Computes the surface area of the cone * @return the surface area of the cone */ public double getSurfaceArea() { double length = Math.sqrt(radius * radius + height * height); double area= Math.PI * radius *(radius*length); return area; } }
Learning Objectives After completion of this lab, you should be able to: 1. Write a Java class to represent an Sphere, Cylinder and Cone type Write Java classes to represent Geometry types 1. Create a new Java class named Sphere In addition, the Sphere class should have the following methods. Constructor The constructor should accept the radius of the sphere. o These values should be used to initialize the Sphere fields getVolume - Write a getVolume() method that will have no parameters o Compute and return the volume of sphere. getSurfaceArea - Write a getSurfaceArea() method that will have no parameters. o Compute and return the surface area of sphere. 2. Create a new Java class named Cylinder In addition, the Cylinder class should have the following methods. Constructor The constructor should accept the radius and height of the cylinder o These values should be used to initialize the Cylinder fields getVolume - Write a getVolume() method that will have no parameters. o Compute and return the volume of Cylinder. getSurfaceArea - Write a getSurfaceArea() method that will have no parameters. o Compute and return the surface area of Cylinder. 3. Create a new Java class named Cone In addition, the Cone class should have the following methods. Constructor The constructor should accept the radius and height of the cone. o These value should be used to initialize the Cone fields getVolume - Write a getVolume() method that will have no parameters. o Compute and return the volume of the cone. getSurfaceArea Write a getSurfaceArea() method that will have no parameters. o Compute and return the surface area of the cone. BE SURE TO COMMENT YOUR CODE JAVADOC STYLE!! Comment stating what method is doing. @params // explain input parameter(s) to method @returns // explain what method is returning Pre & Post conditions o See notes and book

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

More Books

Students also viewed these Databases questions

Question

Are you really powerful and perceived as such by others?

Answered: 1 week ago