Question

I am trying to write a Geometry.java program but Dr.Java is giving me errors and I...

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
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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)?:

Add a comment
Know the answer?
Add Answer to:
I am trying to write a Geometry.java program but Dr.Java is giving me errors and I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Project Objectives: To develop ability to write void and value returning methods and to call them...

    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 {...

    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:...

    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...

  • I am having trouble finding any logical errors...Any advise? Thank you public class Brick { //...

    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...

    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') {...

  • // please i cant understand why this program isnot running HELP me please? import java.util.Scanner; public...

    // please i cant understand why this program isnot running HELP me please? import java.util.Scanner; public class String { public static void main(String[] args) { double Sside, Rlength, Rwidth, Tbase, Theight, Area, Tarea, Rarea; String input; Scanner keyboard = new Scanner(System.in); System.out.print("To Calculate the are of Square Enter 'Square', For Rectangle Enter 'Rectangle', For Triangle Enter 'Triangle'"); input = keyboard.nextLine(); if (input.equalsIgnoreCase("SQUARE")) { System.out.println("Square Side"); Sside = keyboard.nextInt(); Tarea = Sside * Sside; System.out.println("Side = " + Tarea ); }...

  • this is what i have so far but it does not work. please help thank you...

    this is what i have so far but it does not work. please help thank you Part 2: Perimeter of a Triangle Write a program named Triangle.java that asks for the lengths of the three sides of a triangle and computes the perimeter if the input is valid.The input is valid if the sum of every pair of two sides is greater than the remaining side. For example, the lengths 3, 4, and 5 define a valid triangle: 3 plus...

  • write a completed program (included the main) for the Q: add an equals method to each...

    write a completed program (included the main) for the Q: add an equals method to each of the Rectangle circle and triangle classes introduced in this chapter. two shapes are considered equal if their fields have equivalent values. based on public class Circle implements Shape f private double radius; // Constructs a new circle with the given radius. public Circle (double radius) f this.radius - radius; // Returns the area of this circle. public double getArea) return Math.PI *radius *...

  • I have this program: It passes on certain test cases. The Demo five has the %.1f...

    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 Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a...

    I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a void method named howToColor(). void howToColor(); } GeometricObject class: public class GeometricObject { } Sqaure class: public class Square extends GeometricObject implements Colorable{ //side variable of Square double side;    //Implementing howToColor() @Override public void howToColor() { System.out.println("Color all four sides."); }    //setter and getter methods for Square public void setSide(double side) { this.side = side; }    public double getSide() { return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT