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 the rectangle
double width; // The width of the rectangle
double height; // The height of the triangle
double base; // The base of the triangle
double side1; // The first side of the triangle
double side2; // The second side of the triangle
double side3; // The third side of the triangle
// Create a scanner object to read from the keyboard
Scanner keyboard = new Scanner(System.in);
// The do loop allows the menu to be displayed first
do
{
// TASK #1 Call the printMenu method
printMenu();
choice = keyboard.nextInt();
switch(choice)
{
case 1:
System.out.print("Enter the radius of " +
"the circle: ");
radius = keyboard.nextDouble();
// TASK #3 Call the circleArea method and
// store the result in the value variable
value=cirArea(radius);
System.out.println("The area of the " +
"circle is " + value);
break;
case 2:
System.out.print("Enter the length of " +
"the rectangle: ");
length = keyboard.nextDouble();
System.out.print("Enter the width of " +
"the rectangle: ");
width = keyboard.nextDouble();
// TASK #3 Call the rectangleArea method and
// store the result in the value variable
value=recArea(length, width);
System.out.println("The area of the " +
"rectangle is " + value);
break;
case 3:
System.out.print("Enter the height of " +
"the triangle: ");
height = keyboard.nextDouble();
System.out.print("Enter the base of " +
"the triangle: ");
base = keyboard.nextDouble();
// TASK #3 Call the triangleArea method and
// store the result in the value variable
value=triArea(base,height);
System.out.println("The area of the " +
"triangle is " + value);
break;
case 4:
System.out.print("Enter the radius of " +
"the circle: ");
radius = keyboard.nextDouble();
// TASK #3 Call the circumference method and
// store the result in the value variable
value= cirCircumference(radius);
System.out.println("The circumference " +
"of the circle is " +
value);
break;
case 5:
System.out.print("Enter the length of " +
"the rectangle: ");
length = keyboard.nextDouble();
System.out.print("Enter the width of " +
"the rectangle: ");
width = keyboard.nextDouble();
// TASK #3 Call the perimeter method and
// store the result in the value variable
value=recPerimeter(length,width);
System.out.println("The perimeter of " +
"the rectangle is " +
value);
break;
case 6:
System.out.print("Enter the length of " +
"side 1 of the " +
"triangle: ");
side1 = keyboard.nextDouble();
System.out.print("Enter the length of " +
"side 2 of the " +
"triangle: ");
side2 = keyboard.nextDouble();
System.out.print("Enter the length of " +
"side 3 of the " +
"triangle: ");
side3 = keyboard.nextDouble();
// TASK #3 Call the perimeter method and
// store the result in the value variable
value=triPerimeter(side1,side2,side3);
System.out.println("The perimeter of " +
"the triangle is " +
value);
break;
default:
System.out.println("You did not enter " +
"a valid choice.");
}
keyboard.nextLine(); // Consume the new line
System.out.println("Do you want to exit " +
"the program (Y/N)?: ");
String answer = keyboard.nextLine();
letter = answer.charAt(0);
} while(letter != 'Y' && letter != 'y');
}
// TASK #1 Create the printMenu method here
public static void printMenu(){
System.out.println("This is a geometry calculator");
System.out.println("Choose what you would like to
calculate");
System.out.println("1. Find the area of a circle");
System.out.println("2. Find the area of a rectangle");
System.out.println("3.Find the area of a triangle");
System.out.println("4. Find the circumference of a circle");
System.out.println("5. Find the perimeter of a rectangle");
System.out.println("6. Find the perimeter of a triangle Enter the
number of your choice:");
// TASK #2 Create the value-returning methods here
/**
*
*
*
*/
public static double cirArea(double radius)
{
return Math.Pi*radius*radius;
}
/**
*
*
*
*/
public static double recArea(double length,double width){
return lenght*width;
}
/**
*
*
*
*/
public static double triArea(double base,double height){
return 0.5*base*height;
}
/**
*
*
*
*/
public static double cirCircumference(double radius){
return 2*Math.Pi*radius;
}
/**
*
*
*/
public static double recPerimeter(double length,double
width){
return 2*(length+width);
}
/**
*
*
*/
public static double triPerimeter(double side1,double side2,double
side3);
{
return side1+side2+side3;
}
// TASK #4 Write javadoc comments for each method
}
}
import java.util.Scanner;
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 the rectangle
double width; // The width of the rectangle
double height; // The height of the triangle
double base; // The base of the triangle
double side1; // The first side of the triangle
double side2; // The second side of the triangle
double side3; // The third side of the triangle
// Create a scanner object to read from the keyboard
Scanner keyboard = new Scanner(System.in);
// The do loop allows the menu to be displayed first
do {
// TASK #1 Call the printMenu method
printMenu();
choice = keyboard.nextInt();
switch (choice) {
case 1:
System.out.print("Enter the radius of " + "the circle: ");
radius = keyboard.nextDouble();
// TASK #3 Call the circleArea method and
// store the result in the value variable
value = cirArea(radius);
System.out.println("The area of the " + "circle is " + value);
break;
case 2:
System.out.print("Enter the length of " + "the rectangle: ");
length = keyboard.nextDouble();
System.out.print("Enter the width of " + "the rectangle: ");
width = keyboard.nextDouble();
// TASK #3 Call the rectangleArea method and
// store the result in the value variable
value = recArea(length, width);
System.out.println("The area of the " + "rectangle is " + value);
break;
case 3:
System.out.print("Enter the height of " + "the triangle: ");
height = keyboard.nextDouble();
System.out.print("Enter the base of " + "the triangle: ");
base = keyboard.nextDouble();
// TASK #3 Call the triangleArea method and
// store the result in the value variable
value = triArea(base, height);
System.out.println("The area of the " + "triangle is " + value);
break;
case 4:
System.out.print("Enter the radius of " + "the circle: ");
radius = keyboard.nextDouble();
// TASK #3 Call the circumference method and
// store the result in the value variable
value = cirCircumference(radius);
System.out.println("The circumference " + "of the circle is " + value);
break;
case 5:
System.out.print("Enter the length of " + "the rectangle: ");
length = keyboard.nextDouble();
System.out.print("Enter the width of " + "the rectangle: ");
width = keyboard.nextDouble();
// TASK #3 Call the perimeter method and
// store the result in the value variable
value = recPerimeter(length, width);
System.out.println("The perimeter of " + "the rectangle is " + value);
break;
case 6:
System.out.print("Enter the length of " + "side 1 of the " + "triangle: ");
side1 = keyboard.nextDouble();
System.out.print("Enter the length of " + "side 2 of the " + "triangle: ");
side2 = keyboard.nextDouble();
System.out.print("Enter the length of " + "side 3 of the " + "triangle: ");
side3 = keyboard.nextDouble();
// TASK #3 Call the perimeter method and
// store the result in the value variable
value = triPerimeter(side1, side2, side3);
System.out.println("The perimeter of " + "the triangle is " + value);
break;
default:
System.out.println("You did not enter " + "a valid choice.");
}
keyboard.nextLine(); // Consume the new line
System.out.println("Do you want to exit " + "the program (Y/N)?: ");
String answer = keyboard.nextLine();
letter = answer.charAt(0);
} while (letter != 'Y' && letter != 'y');
}
// TASK #1 Create the printMenu method here
public static void printMenu() {
System.out.println("This is a geometry calculator");
System.out.println("Choose what you would like to calculate");
System.out.println("1. Find the area of a circle");
System.out.println("2. Find the area of a rectangle");
System.out.println("3.Find the area of a triangle");
System.out.println("4. Find the circumference of a circle");
System.out.println("5. Find the perimeter of a rectangle");
System.out.println("6. Find the perimeter of a triangle Enter the number of your choice:");
}
// TASK #2 Create the value-returning methods here
/**
*
*
*
*/
public static double cirArea(double radius) {
return Math.PI * radius * radius;
}
/**
*
*
*
*/
public static double recArea(double length, double width) {
return length * width;
}
/**
*
*
*
*/
public static double triArea(double base, double height) {
return 0.5 * base * height;
}
/**
*
*
*
*/
public static double cirCircumference(double r) {
return 2 * Math.PI * r;
}
/**
*
*
*/
public static double recPerimeter(double length, double width) {
return 2 * (length + width);
}
/**
*
*
*/
public static double triPerimeter(double side1, double side2, double side3) {
return side1 + side2 + side3;
}
// TASK #4 Write javadoc comments for each method
}
![terminated> Geometry Uava Application] CAProgram FilesJavaire1.8.0_144\binjavaw.exe (Nov 2, 2018, 8:51:04 AM) This is a geometry calculator Choose what you would like to calculate 1. Find the area of a circle 2. Find the area of a rectangle 3.Find the area of a triangle 4. Find the circumference of a circle 5. Find the perimeter of a rectangle 6. Find the perimeter of a triangle Enter the number of your choice: Enter the radius of the circle: 4 The area of the circle is 50.26548245743669 Do you want to exit the program (Y/N)?:](http://img.homeworklib.com/questions/a58b7890-8aa3-11eb-ba27-c36bfc7f7223.png?x-oss-process=image/resize,w_560)
I am trying to write a Geometry.java program but Dr.Java is giving me errors and I...
JAVA Code Requried Copy the file java included below. This program will compile, but, when you run it, it doesn’t appear to do anything except wait. That is because it is waiting for user input, but the user doesn’t have the menu to choose from yet. We will need to create this. Below the main method, but in the Geometry class, create a static method called printMenu that has no parameter list and does not return a value. It will...
Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...
Why is my program returning 0 for the area of a triangle? public class GeometricObjects { private String color = " white "; private boolean filled; private java.util.Date dateCreated; public GeometricObjects() { dateCreated = new java.util.Date(); } public GeometricObjects(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } public String getColor() { return color; } public void setColor(String color)...
Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3: 5 Enter the base: 5 Enter the height: 8 --------------------- The triangle is Isosceles since it has two equal length sides. Isosceles triangle also has two equal angles The area is: 20 The permimeter is: 13 Continue? (y/n): y Enter length 1: 10 Enter length 2: 10 Enter length 3: 10 Enter the base: 10 Enter the height: 7 --------------------- The triangle is Equilateral...
Objective Extend the class GeometicShapes to include a Triangle class.. Background Reading ZyBooks Chapter 10 Task Create the following fields and methods for a Triangle class that extends the provided GeometricShapes class public class GeometricShapes { private String color = "red"; private boolean filled; private java.util.Date dateCreated; public GeometricShapes() { dateCreated = new java.util.Date(); } public GeometricShapes(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } public void setColor (String color)...
IN C++ You are to write a program which will get the following variables from the user. Length, Width, Height, Radius, Base. You should also have variables for Pi as 3.14 and choice1 and choice2. Your program will first ask the following: Press 1 to calculate Area Press 2 to calculate Perimeter The choice will be saved in choice1. You should then ask another choice: Press 1 for Rectangle Press 2 for Triangle Press 3 for Circle You have all...
Design a general class GeometricObject can be used to model all geometric objects. This class contains the properties color and filled and their appropriate get and set methods. Assume that this class also contains toString() methods. The toString() method returns a string representation of the object. Define the Triangle, Circle, and Rectangle classes that extend the GeometricObject class. The Triangle class inherits all accessible data fields and methods from the GeometricObject class.In addition, it has three double data fields named...
I am having trouble finding any logical errors...Any advise? Thank you public class Brick { // Constant. private static final int WEIGHT_PER_CM3 = 2; // weight per cubic cm in grams private int height; private int width; private int depth; /** * Create a Brick given edge lengths in centimeters. * @param height The brick's height. * @param width The brick's width. * @param depth The brick's depth. */ public Brick(int height, int width, int depth) { this.height = height;...
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') {...
(Need to complete the methods and pass a Junit test i can email them to you.) public class Triangle implements Comparable { /** * Stores the number of objects instantiated from the {@code Triangle} class */ private static int numTriangles; /** * The shortest side of the triangle */ private final double a; /** * The side of medium length of the triangle */ private final double b;...