Most specifically the methods to findConicalFrustum and editConicalFrustum in Co
ID: 3722645 • Letter: M
Question
Most specifically the methods to findConicalFrustum and editConicalFrustum in ConicalFrustumList and correspinding switch cases in ConicalFrustumMenuListApp.
ConicalFrustum.java ConicalFrustumList.java ConicalFrustumListMenuApp.java Specifications Overview: You will write a program this week that is composed of three classes: the first class defines ConicalFrustum objects, the second class defines ConicalFrustumList objects, and the third, ConicalFrustumListMenuApp, presents a menu to the user with eight options and implements these: (1) read input file (which creates a ConicalFrustumList object), (2) print report, (3) print summary (4) add a ConicalFrustum object to the ConicalFrustumList object, (5) delete a ConicalFrustum object from the ConicalFrustumList object, (6) find a ConicalFrustum object in the ConicalFrustumList object, (7) Edit a ConicalFrustum in the ConicalFrustumList object, and (8) quit the program. [You A Conical Frustum is a Frustum created by slicing the top off a cone (with the cut made parallel to the base), forming a lower base and an upper base that are circular and parallel radius of top r radius of bottom h height s slant height S lateral surface area V volume A total surface area |s=*(r1 +T2) * s Source for figures and formulas: https://www.calculatorsoup.com/images/frustum001.gifExplanation / Answer
//ConicalFrustum.java
import java.io.*;
import java.util.*;
class ConicalFrustum {
//defining memebers
public static final double PI = 3.14;
private String label = "";
private double radius1 = 0;
private double radius2 = 0;
private double height = 0;
//defining contructor with 4 arguments
public ConicalFrustum(String labelIn, double radius1In, double radius2In, double heightIn) {
setLabel(labelIn);
setRadius1(radius1In);
setRadius2(radius2In);
setHeight(heightIn);
}
public boolean setLabel(String labelIn) {
if (!labelIn.equals("")) {
label = labelIn;
return true;
}
return false;
}
public boolean setRadius1(double radius1In) {
if (radius1In >= 0) {
radius1 = radius1In;
return true;
}
return false;
}
public boolean setRadius2(double radius2In) {
if (radius2In >= 0) {
radius2 = radius2In;
return true;
}
return false;
}
public boolean setHeight(double heightIn) {
if (heightIn >= 0) {
height = heightIn;
return true;
}
return false;
}
public String getLabel() {
return label;
}
public double getRadius1() {
return radius1;
}
public double getRadius2() {
return radius2;
}
public double getHeight() {
return height;
}
public double volume() {
double r1 = getRadius1(), r2 = getRadius2(), h = getHeight();
return (1 / 3) * PI * h * ((r1 * r1) * (r2 * r2) + (r1 * r2));
}
public double slantHeight() {
double r1 = getRadius1(), r2 = getRadius2(), h = getHeight();
return Math.sqrt(Math.pow(r1 - r2, 2) + (h * h));
}
public double lateralSurfaceArea() {
double r1 = getRadius1(), r2 = getRadius2(), h = getHeight();
return Math.PI * (r1 + r2) * slantHeight();
}
public double totalSurfaceArea() {
double r1 = getRadius1(), r2 = getRadius2(), h = getHeight();
return Math.PI *((r1*r1)+(r2*r2)+(r1+r2)*slantHeight());
}
public String toString() {
String str = "ConicalFrustum " + getLabel() + " with radius1 = " + getRadius1() + ", radius1 = " + getRadius2()
+ ", height = " + getHeight() + " has:";
str += " volume = " + volume() + " cubic units slant height = " + slantHeight()
+ " units lateral surface area = " + lateralSurfaceArea() + " units total surface area = "
+ totalSurfaceArea() + " square units";
return str;
}
}
//ConicalFrustumList.java
import java.io.*;
import java.util.*;
class ConicalFrustumList {
private String name;
private List<ConicalFrustum> list = new ArrayList<ConicalFrustum>();
ConicalFrustumList(String nameIn) {
name = nameIn;
}
public String getName() {
return name;
}
public int numberOfConicalFrustums() {
return list.size();
}
public double totalSurfaceArea() {
double res = 0;
for (ConicalFrustum el : list) {
res += el.totalSurfaceArea();
}
return res;
}
public double totalVolume() {
double res = 0;
for (ConicalFrustum el : list) {
res += el.volume();
}
return res;
}
public double averageVolume() {
return totalVolume() / numberOfConicalFrustums();
}
public double averageSurfaceArea() {
return totalSurfaceArea() / numberOfConicalFrustums();
}
public String toString() {
String str = getName();
System.out.println(list.size());
for (ConicalFrustum el : list) {
str += " " + el.toString() + " ";
}
return str;
}
public String summaryInfo() {
String str = "---------- Summary for " + getName() + " ------------ ";
str += "Number of ConicalFrustum Objects: " + numberOfConicalFrustums() + " ";
str += "Total Surface Area: " + totalSurfaceArea() + " ";
str += "Total Volume: " + totalVolume() + " ";
str += "Average Surface Area: " + averageSurfaceArea() + " ";
str += "Average Volume: " + averageVolume() + " ";
return str;
}
public List<ConicalFrustum> getList() {
return list;
}
public void readFile(String fileName) {
try {
File file = new File(fileName);
Scanner sc = new Scanner(new FileReader(file));
String label;
double radius1, radius2, height;
while (sc.hasNextLine()) {
label = sc.next();
radius1 = sc.nextDouble();
radius2 = sc.nextDouble();
height = sc.nextDouble();
addConicalFrustum(label, radius1, radius2, height);
}
} catch (FileNotFoundException e) {
System.out.println("File Not found");
}
}
public void addConicalFrustum(String labelIn, double radius1In, double radius2In, double heightIn) {
ConicalFrustum newItem = new ConicalFrustum(labelIn, radius1In, radius2In, heightIn);
list.add(newItem);
}
public ConicalFrustum findConicalFrustum(String label) {
for (ConicalFrustum el : list) {
if (el.getLabel() == label) {
return el;
}
}
return null;
}
public boolean deleteConicalFrustum(String label) {
for (ConicalFrustum el : list) {
if (el.getLabel() == label) {
list.remove(el);
return true;
}
}
return false;
}
public boolean editConicalFrustum(String labelIn, double radius1In, double radius2In, double heightIn) {
for (ConicalFrustum el : list) {
if (el.getLabel() == labelIn) {
el.setRadius1(radius1In);
el.setRadius2(radius2In);
el.setHeight(heightIn);
return true;
}
}
return false;
}
}
//ConicalFrustumListAppMenu,java
import java.io.*;
import java.util.*;
class ConicalFrustumListMenuApp {
public static void main(String[] args) {
char choice;
ConicalFrustumList list = new ConicalFrustumList("Testing");
do{
System.out.println("Conical Frustum List System Menu");
System.out.println("R - Read File and Create ConicalFrustum List");
System.out.println("P - Print ConicalFrustum List");
System.out.println("S - Print Summary");
System.out.println("A - Add ConicalFrustum");
System.out.println("D - Delete ConicalFrustum");
System.out.println("F - Find ConicalFrustum");
System.out.println("E - Edit ConicalFrustum");
System.out.println("Q - Quit");
System.out.println("Enter Code [R, P, S, A, D, F, E, or Q]: ");
Scanner in = new Scanner(System.in);
choice = in.next().charAt(0);
switch (choice) {
case 'R': {
String file;
System.out.print("Enter File name: ");
file = in.next();
list.readFile(file);
System.out.println("File read in and ConicalFrustum List created");
break;
}
case 'P':
System.out.println(list.getList().size());
System.out.println(list.toString());
break;
case 'S':
System.out.println(list.summaryInfo());
break;
case 'A': {
String label;
double radius1, radius2, height;
System.out.println("Label: ");
label = in.next();
System.out.println("Radius1: ");
radius1 = in.nextDouble();
System.out.println("Radius2: ");
radius2 = in.nextDouble();
System.out.println("Height: ");
height = in.nextDouble();
list.addConicalFrustum(label, radius1, radius2, height);
System.out.println("*** ConicalFrustum added ***");
break;
}
case 'D': {
String label;
System.out.println("Label: ");
label = in.next();
if (list.deleteConicalFrustum(label)) {
System.out.println(""" + label + "" deleted");
} else {
System.out.println(""" + label + "" not found");
}
}
break;
case 'F': {
String label;
System.out.print("Label: ");
label = in.next();
ConicalFrustum r = list.findConicalFrustum(label);
if (r == null) {
System.out.println(""" + label + "" not found");
} else {
r.toString();
}
break;
}
case 'E': {
String label;
double radius1, radius2, height;
System.out.println("Label: ");
label = in.next();
System.out.println("Radius1: ");
radius1 = in.nextDouble();
System.out.println("Radius2: ");
radius2 = in.nextDouble();
System.out.println("Height: ");
height = in.nextDouble();
if(list.editConicalFrustum(label, radius1, radius2, height))
System.out.println("""+label+"" successfully edited");
else{
System.out.println("""+label+"" not found");
}
break;
}
case 'Q':
System.exit(1);
break;
default:
System.out.println("***** Invalid code *****");
}
}while(choice!='Q');
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.