******** IN JAVA *********
I have a program that I need help debugging. This program should ask a user to input 3 dimensions of a rectangular block (length, width, and height), and then perform a volume and surface area calculation and display the results of both. It should only be done using local variables via methods and should have 4 methods: getInput, volBlock, saBlock, and display (should be void). I have most of it written here:
import java.util.*;
public class Block {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String choice = "Y";
while (choice.equals("Y")){
getInput();
System.out.println("Would you like to do another calculation?(Y/N):
");
choice = in.next().toUpperCase();
}
System.out.println("Program now ending...");
}
public static void getInput(){
double l, w, h;
Scanner fin = new Scanner(System.in);
System.out.println("Please enter the length, width, and height in
that order: ");
l = fin.nextDouble();
w = fin.nextDouble();
h = fin.nextDouble();
volBlock(l, w, h);
surfaceAreaBlock(l,w,h);
}
public static double volBlock(double length, double width, double
height){
double volume;
volume = length * width * height;
display(volume);
return volume;
}
public static double surfaceAreaBlock (double l, double w, double
h){
double surfaceArea;
surfaceArea = 2 * (l*h+l*w+h*w);
display(surfaceArea);
return surfaceArea;
}
public static void display(double output) {
System.out.println("Volume = " + output);
System.out.println("Surface Area = " + output);
}
}
Special requirements: the getInput method should be used to return 1 double input. It should be called 3 times for length, width, and height respectively.
Block.java :
//import package
import java.util.*;
//Java class
public class Block {
//main() method
public static void main(String[] args) {
//Object of Scanner class
Scanner in = new
Scanner(System.in);
String choice = "Y";//variable used
to store user input
while (choice.equals("Y")) {
double l, w,
h;//declaring variables
double
volume,surfaceArea;//variables used to store volume and
surfaceArea
l=getInput("Enter length");//method call to take length from
user
w=getInput("Enter Width");//method call to take width from
user
h=getInput("Enter Height");//method call to take height from
user
//call method to
calculate volume of block
volume=volBlock(l, w, h);
//call method to
calculate surface area of block
surfaceArea=surfaceAreaBlock(l, w, h);
//call display()
method
display(volume,
surfaceArea);
//asking user
whether want to have another calculation
System.out.println("Would you like to do another calculation?(Y/N):
");
choice =
in.next().toUpperCase();//reading user input and converting to
upper case
}
//show message when program
ends
System.out.println("Program now
ending...");
}
//method to get input from user
public static double getInput(String input) {
double inputParam;//declaring
variable
Scanner fin = new
Scanner(System.in);
System.out.print("Please "+input+"
: ");
inputParam=fin.nextDouble();//reading input
return inputParam;//return
input
}
//method to calculate volume of block
public static double volBlock(double length, double
width, double height) {
double volume;
//calculate volume
volume = length * width *
height;
return volume;//return volume
}
//method to calculate surface area of block
public static double surfaceAreaBlock(double l, double
w, double h) {
double surfaceArea;
//calculate surface Area
surfaceArea = 2 * (l * h + l * w +
h * w);
//return surface Area
return surfaceArea;
}
//method to display details
public static void display(double volume,double
surfaceArea) {
System.out.println("Volume = " +
volume);//print volume
System.out.println("Surface Area =
" + surfaceArea);//print surface area
}
}
===================================
Output :
******** IN JAVA ********* I have a program that I need help debugging. This program should...
This code is in java. Create a Java class that has the private double data of length, width, and price. Create the gets and sets methods for the variables. Create a No-Arg constructor and a constructor that accepts all three values. At the end of the class add a main method that accepts variables from the user as input to represent the length and width of a room in feet and the price of carpeting per square foot in dollars...
I have this program: It passes on certain test cases. The Demo five has the %.1f to cut down the number to one decimal place. But I get a failed attempt such as: Enter length: \n Enter width: \n You entered: 87.3, 2.0, and 174.7\n -- Rectangle info --\n Length: 87.34\n Width: 2.0\n Area: 174.68\n And I know it is because the length and area both have 2 decimal places. Could you help me fix this? Thank you. Program Content:...
I have a program that reads a file and then creates objects from the contents of the file. How can I create a linked list of objects and use it with the package class instead of creating and using an array of objects? I am not allowed to use any arrays of objects or any java.util. lists in this program. Runner class: import java.util.Scanner; import java.io.*; class Runner { public static Package[] readFile() { try { File f = new...
Please, modify the code below to use the Switch Statements in Java instead of “if” statements to make the decisions. import java.util.Scanner; public class Area { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter code(C for circle, R for rectangle, S for square): "); char code = in.next().charAt(0); if(code == 'C') { System.out.print("Enter radius: "); double radius = in.nextDouble(); System.out.println("Area of circle is " + (Math.PI * radius * radius)); } else if(code == 'R') {...
I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...
I need help with a java error Question: Consider a graphics system that has classes for various figures—say, rectangles, boxes, triangles, circles, and so on. For example, a rectangle might have data members’ height, width, and center point, while a box and circle might have only a center point and an edge length or radius, respectively. In a well-designed system, these would be derived from a common class, Figure. You are to implement such a system. The class Figure is...
I need help with a java error Question: Consider a graphics system that has classes for various figures—say, rectangles, boxes, triangles, circles, and so on. For example, a rectangle might have data members’ height, width, and center point, while a box and circle might have only a center point and an edge length or radius, respectively. In a well-designed system, these would be derived from a common class, Figure. You are to implement such a system. The class Figure is...
Write a program that stores a phrase as an array of words, and then prints it backwards. The main method calls method getInput , which asks the user how many words there are, stores them in an array, and returns this array. printBackwards then takes this array of words, and prints it in reverse. Code Example: import java.util.Scanner; public class L17Num1{ public static void main(String[] args) { String[] sArray=getInput(); printBackwards(sArray); } public static String[] getInput() { System.out.println("How many...
I need help debugging this Java program. I am getting this error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at population.Population.main(Population.java:85) I am not able to run this program. ------------------------------------------------------------------- import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; /* Linked list node*/ class node { long data; long year; String country; node next; node(String c,long y,long d) { country=c; year=y; data = d; next = null; } } public class Population { private static node head; public static void push(String...
JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in); System.out.println("Seed:"); int seed = scanner.nextInt(); System.out.println("Length"); int length = scanner.nextInt(); Random random...