*JAVA*
Assume that there already exists a class called ThreeDimensionalShape. Assume that this class has many subclasses, one of them being Cylinder. Assume that ThreeDimensionalShape has an instance method called getVolume() that returns the volume of the object (a double) and that this method is overridden in all of the subclasses. (You do not need to write any of these classes.)
Write a method with this header: public static double volumeOfCylinders( ThreeDimensionalShapes[] shapes)
It should return a value representing the volume of all the Cylinders in the array
abstract class ThreeDimensionalShapes
{
public abstract double getVolume();
};
class Cylinder extends ThreeDimensionalShapes
{
private double radius;
private double height;
public Cylinder(double radius,double height)
{
this.radius = radius;
this.height = height;
}
public double getVolume()
{
return 3.14*radius*radius*height;
}
}
class Test
{
public static void main (String[] args)
{
ThreeDimensionalShapes[] shapes = new
Cylinder[3];
shapes[0] = new Cylinder(4.3,6.6);
shapes[1] = new Cylinder(3.3,4.6);
shapes[2] = new Cylinder(2.3,2.6);
System.out.printf("Volume of all cylinders :
%.2f",volumeOfCylinders(shapes));
}
public static double volumeOfCylinders(
ThreeDimensionalShapes[] shapes)
{
double totalVolume = 0.0;
for(int
i=0;i<shapes.length;i++)
{
System.out.println("Volume of cylinder "+(i+1)+" :
"+shapes[i].getVolume());
totalVolume +=
shapes[i].getVolume();
}
return totalVolume;
}
}
Output:
Volume of cylinder 1 : 383.18676 Volume of cylinder 2 : 157.29515999999998 Volume of cylinder 3 : 43.18756 Volume of all cylinders : 583.67
Do ask if any doubt. Please up-vote.
*JAVA* Assume that there already exists a class called ThreeDimensionalShape. Assume that this class has many...
This must be done in Java and it must contain a public static void (string []args) 10.13 (Project: Shape Hierarchy) Implement the Shape hierarchy shown in Fig. 9.3. Each TwoDimensionalShape should contain method getArea to calculate the area of the two-dimensional shape. Each ThreeDimensionalShape should have methods getArea and getVolume to calculate the surface area and volume, respectively, of the three-dimensional shape. Create a program that uses an array of Shape references to objects of each concrete class in the hierarchy. The program...
Create a Bitbucket private repository. Name it “CUS1156_Lab2”. Clone it in your local java Eclipse workspace. You will add the java files after you have completed them in Part 1 and Part 2 to this location. Part 1: Abstract classes From class, an abstract class represents some generic concept. Subclasses then provide their own specific implementations of any abstract methods of the abstract class. 1. Implement an abstract class called Shape it was discussed in the lecture. Include an abstract...
Create class definitions using the following: Classes: Circle, Cube, Shape, Sphere, Square, ThreeDimensionalShape, TwoDimensionalShape Functions: Draw, GetArea, GetDimensions, GetHeight, GetLength, GetSurfaceArea, GetVolume Members: height, length, width – all of type double Don’t actually write function implementations, just define the classes as you would in a header file. Use inheritance as appropriate. Use keywords such as “const” and “virtual” as appropriate. Make functions and members public, private, or protected as appropriate. Don’t forget constructors and destructors. Some classes may be abstract,...
public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which does the following: In the main method: Use a for loop which repeats three times. Within the loop, a. prompt the user to enter the base of the triangular prism and store the value in a double array called base b. prompt the user to enter the corresponding height and store the value in a double array called height c. prompt the user to...
Objective: in Java Write a program that implements 3 sorting algorithms and times them in real time. These algorithms will sort Cylinders by their volume. First, download the driver and include it in your project. Write a class Cylinder with the following properties baseRadius: a non-negative number that corresponds to the Cylinder’s base’s radius. height: a non-negative number that corresponds to the Cylinder’s height. Next, write a class Sorter with the following bubbleSort: This static method takes in an array...
THIS IS IN THE JAVA SCRIPT CODE
ALSO PLEASE SEND ME THE CODE TYPED THANK YOU.
Program 1 Write an inheritance hierarchy of three-dimensional shapes. Make a top-level shape interface that has methods for getting information such as the volume and the surface area of a three-dimensional shape. Then make classes and subclasses that implement various shapes such as cube, cylinders and spheres. Place common behavior in superclasses whenever possible, and use abstract classes as appropriate. Add methods to the...
Need help to create general
class
Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...
Create a class called DuplicateRemover. Create an instance method called remove that takes a single parameter called dataFile (representing the path to a text file) and uses a Set of Strings to eliminate duplicate words from dataFile. The unique words should be stored in an instance variable called uniqueWords. Create an instance method called write that takes a single parameter called outputFile (representing the path to a text file) and writes the words contained in uniqueWords to the file pointed...
JAVA I. Using the Event Class created previously, create an array of objects; II. Demonstrate passing array reference to a method; III. Demonstrate creating array of objects that prints out only x 0.0 for all objects. PROJECT 5C - ARRAYS Create a new file called " EventArray5C". There are some "challenging" directions in this project. . 1.Prepare a document box (tell me that task(s) the application is to accomplish, how it will accomplish the tasks, the author of...
Java: Create a class called Vehicle with the following features: a. It has three private data members (instance variables): one is the manufacturer’s name (String manufacturer), the second is the number of cylinders in the engine (int cylinder), and the third is the owner (Person owner). The class Person is described above. b. It has three constructors, a no-argument constructor, a constructor with three parameters, and a copy constructor. The no-argument constructor will set the manufacturer to “None”, cylinder to...