Question: I need to fix this program but must keep the same format. I am trying to calculate volume of triangle which the formula isv=0.5*h*a*b.keep using

I need to fix this program but must keep the same format. I am trying to calculate volume of triangle which the formula isv=0.5*h*a*b.keep using the wrapper class parseDouble to convert the string into double like this format:

Scanner stdIn = new Scanner(System.in);

String baseStr;

double base;

System.out.print("Enter the Width of the Square:");

baseStr = stdIn.nextLine();

base = Double.parseDouble(baseStr);

Here is my program that needs fix

/********************************************

*TraingleVolume.java

*

*This program calculates the volume of a Traingle

********************************************/

import java.util.Scanner;

public class CubeVolume

{

public static void main(String[]args)

{

Scanner stdIn = new Scanner(System.in);

String height

String altitude

String base

double volume;

System.out.println("This will calculate the volume of a traingle");

System.out.println("Please input the height of traingle: ");

height = stdIn.nextLine();

System.out.println("Please input the altitude of traingle: ");

altitude = stdIn.nextLine();

System.out.println("Please input the base of traingle: ");

base = stdIn.nextLine();

volume = Math.pow(Double.parseDouble(height), (altitude), (base), 0.5); //calculation while also converting string to primitive

System.out.printf("The volume of the traingle = %.2f ", volume); //displays double and two digits after decimal

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!