I'm creating a program to calculate a triangle and a rectangle
843789Jun 5 2009 — edited Jun 5 2009Hello, my calculateAreaOfShapes program is designed to give the user a choice between calculating the area of a triangle, verses a rectangle. my code for that part goes like this:
import java.util.Scanner;
public class ModifiedTestCalculateAreaOfShapes
{
public static void main(String[] args);
Student Royce = new Student();
//call student class's print method from student
Royce.printMyInfo();
//Welcome to Royce's modified TestCalculaterAreaOfShapes Program!
System.out.println("Welcome to the Royce ModifiedTestCalculate area program");
System.out.println("Please enter t to calculate area of triangle or r rectangle");
//create a Scanner object name sc
Scanner sc = new Scanner(System.in);
//modifing this assignment so that the user has a choice until choice isn't equal to "r" or "R", or "t" or "T".
String choice = ("y"); //Declare the variable to hold the name
while(!choice.equalsIgnoreCase ("x")); *//Begin program loop*
{
*//get the users choice "t" or "r"*
System.out.print ("Enter (t/r): ");
String user = sc.next();
System.out.print("Enter shape: ");
double shape = sc.nextShape();
System out.println("Please enter t to calculate area of triangle, r for recctangle or x to quit\n")
*//Asking the user to make a choice*.
*//create a Scanner object for if statements/*
if(choice1.equals("t")) //If choice is t then call calculateAreaOfShapes for my code
*//calculate the area of a Rectangle and a Triangle*
CalculateAreaOfShape.Shapes = new CalculateAreaOfShapes();
{
double TriangleArea = Shapes.calculateAreaOfTriangle(height*base)/2
}
else if(choice1.equals("r"));
{
double RectangleArea = Shapes.calculateAreaOfRectangle(height,width);
}
{
*//display the area for each*
String message = "Area for triangle: " + areafortriangle + "\n"
+ "Area for rectangle:" + areaforrectangle + "\n"
+ "Total area: " + total + "\n";
System.out.println(message);
}
*//see if the user wants to continue*
System.out.print(Continue? (r/t): ")
Could someone please help me to include "if" statements? The area of my triangle is (height * base)/2
Also, could someone please help me with corretions for my code. I'm getting confused as to where to place my curly brackets. I know they represent a block of code.
Thanks.{code}{code}