Calculate Surface Area And Volume Of A Cone
Sep 24, 2014
My homework is to find the surface area and volume of a cone. I have 2 individual java program for the homework and one them already works.
public class Cone {
Cone() {}
double r, h;
double volume() {
return (1.0 / 3.0) * Math.PI * r * r * h;
[Code] ....
The second one I keep getting error mainCone.java:22: error: reached end of file while parsing
public class Conemain {
public static void main(String [] args) {
Cone = new Cone();
Cone.setR(5);
Cone.setH(8);
[Code] ....
I need fixing the second one in order to find the surface area and the volume for cone.
View Replies
ADVERTISEMENT
Sep 9, 2014
Write a Java program that calculates the area and volume of a cube, sphere, cylinder, and regular tetrahedron. Your program should obtain the necessary input for each of the objects from the console and output the input, area, and volume of the object. Use appropriate messages to guide the user of your program.
View Replies
View Related
Sep 10, 2014
Write a Java program that calculates the area and volume of a cube, sphere, cylinder, and regular tetrahedron. Your program should obtain the necessary input for each of the objects from the console and output the input, area, and volume of the object. Use appropriate messages to guide the user of your program.
Here what i did, i am not sure if this is what the assignment want, but this is the best method i could come up with
//Khang Le
import java.util.Scanner;
public class InputAreaVolume {
public static void main(String[] args) {
[Code]......
View Replies
View Related
Jan 29, 2015
How do you use power of math. I'm trying to write a calculator to calculate the volume of a cylinder by asking the user to enter the height and radius but when I use pow(2) it doesn't work. I imported java.lang.math class so i dont have to keep using math. for now my code runs just fine since I'm using radius * radius but I would really luv to use the power instead times each other when i have to use higher powers.
import java.util.Scanner;
import static java.lang.Math.*;
public class Lab2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
[Code] .....
View Replies
View Related
Mar 11, 2015
I'm starting with my version of very basic program: calculating area of circle. And of course it doesn't get well. My question: what is wrong in this code?
public class circleAre{
double radious;
void putData(double radi){
radi = radious;
[Code] .....
View Replies
View Related
Mar 3, 2015
package areatest;
import javax.swing.JOptionPane;
public class AreaTest {
public static double areaTriangle (double length, double width){ //How to calculate the area of a triangle
return .5f * length * width;
[Code] .....
When I try to get the area of a rectangle it gives me 9 no matter what input I give it. When I try to get the area of a triangle it gives me .5 no matter what input I give it. Same with the circle but it always gives me 12.56370...
View Replies
View Related
Mar 5, 2014
I am doing an assignment that is asking for the user to put in the radius of a circle and the program figures out the area, diameter and circumference. It is using 2 different java programs to accomplish this. One with the info on how to get area, diameter and circumference and one is the demo that runs the program. I keep getting errors on my demo.
// Circle Class
public class Circle {
private double rad;
private double Pie;
private double area;
private double diameter;
[Code] .....
View Replies
View Related
Feb 24, 2014
Basically its a program where a user is prompted to enter the length of all three sides of a triangle and the program calculates the area by herons formula and can tell if the triangle is equilateral or Pythagorean. I am having trouble entering a formula to where all three enter sides cant possibly be a triangle. Here is my Program. Where the '?' is stated.
import java.util.Scanner;
public class Triangle {
public static void main(String[] args){
double a;
double b;
double c;
double s;
double x;
double area;
[Code] ....
View Replies
View Related
Feb 16, 2015
Create a program to input the length and width of a rectangle and calculate and print the perimeter and area of the rectangle. To do this you will need to write a Rectangle class and a separate runner class. Your program should include instance variables, constructors, an area method, a perimeter method, a toString method, accessor and mutator methods, and user input. Your runner class should include 3 Rectangle objects. One default rectangle, one coded rectangle, and one user input rectangle. All methods should be tested in the runner class.
This is my code:
import java.util.Scanner;
public class Rectangle {
double length;
double width;
public Rectangle() {
[Code] ...
What have I done??? I have created this program using the few different resources with which I am supplied, but I don't understand the resources.
View Replies
View Related
Apr 27, 2014
I am trying to make a program so that the user has to enter a number for the width and length and it will give the area and perimeter:
import java.util.* ;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class jframe extends JFrame {
private static final int WIDTH = 400;
private static final int HEIGHT = 300;
[Code] ....
It is giving me an error saying that the ExitButtonHandler and ebHandler do not have classes but I don't understand why.
View Replies
View Related
May 27, 2014
I want to get the max volume from a file that I stored in an arraylist but it don't know if this is the way to do it. also I don't know how to print the method in the main method. here is the method that will get the max volume
public Shape3D maxVolume(ArrayList<Shape3D> shapes ){
Shape3D currentMax;
int currentMaxIndex = 0;
for ( int i = 1; i < shapes.size(); i++)
[Code] ....
This is my shape3D class
public abstract class Shape3D implements Comparable<Shape3D>
{
private String type;
public double radious;
public double height;
[Code] ....
View Replies
View Related
Aug 31, 2014
My program never compiled. the code is for a dialog box that calculates the volume of a cylinder, and i know there are simpler codes to do it, but this is the format my teacher wants...Heres the code:
import javax.swing.*;
public class classTwo
{
public static void main(String[] args)
{
String rad, hei, vol;
Scanner joe = new Scanner(System.in);
System.out.println ("Hi, please enter a radius.");
double rad = joe.nextLine();
System.out.println ("Enter a height.");
[code]....
View Replies
View Related
Dec 5, 2014
I am currently building a java music player and need getting the volume control to work. I want to be able to set the computers volume directly using an integer. I've created a slider and put the value into an integer. The part that I am having trouble with is getting the volume to work.
View Replies
View Related
May 17, 2013
I do not understand the getActionCommand and ActionListener concepts. This code does not resolve the volume for length, width, and height.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import java.awt.Container;
public class rectangularSolid extends JApplet implements ActionListener {
[Code] ....
View Replies
View Related
Oct 8, 2014
I am supposed to write a Tester to get the current volume of a balloon that starts with a radius of 0 after it is inflated.This is the balloon:
public class Balloon
{
private double savedRadius;//instance variable
/**constructor!!
Constructs a balloon with a radius
*/
}
[code]....
View Replies
View Related
Sep 7, 2014
I have to produce a program that gives the area of a pentagon. I'm very new to java so I get confused easily. I followed the formula in the textbook but I'm doing something wrong and I don't know what. This is the code I've written.
[import java.util.Scanner;
public class Pentagon {
public static void main(String[]args) {
Scanner input = new Scanner (System.in);
// Prompt for length
[Code] ....
View Replies
View Related
Sep 9, 2014
I am supposed to be doing a class assignment that calculates the area of a triangle and outputs with JOptionPane. I was able to fix some errors, but it's uncovering more errors.Here is my code:
import javax.swing.JOptionPane;
import java.util.*;
import java.text.DecimalFormat;
import java.util.StringTokenizer;
public class Area {
public static void main (String [] args) {
double a, b, c; //Input sides of triangle
double x; //Perimeter of triangle
double area; //Area of triangle
StringTokenizer st;
[code]....
View Replies
View Related
Apr 21, 2014
Here is the code that I wrote out:
//program that calculates the circumference and area of a circle
import java.util.Scanner;
public class circle{
public static void main(String[] args){
Scanner input= new Scanner( System.in);
double r; //declares radius
[Code] .....
And here is what is displayed in the command prompt when I compile my code:
circle.java:17: error: cannot find symbol
r.input.nextdouble();//entered the radius
symbol: method nextdouble()
location: variable input of type Scanner
1 error
What am I doing wrong?
View Replies
View Related
Mar 25, 2015
How to find coordinates of transparent area in the image. I working on .png image which has transparent background and transparent area in the middle of the image. The transparent area in the middle look a like ellipse, so i want to find coordinate of top, bottom, left, and right of that area. I am using opencv.
I have tried to find pixels and from result that i got, i understand that pixel with rgb that equal to 255.0 255.0 255.0 is transparent. what i have in my mind is, if rgb with value that equal to 255 255 255 detected, i will put 1 into arraylist named transparent, and if it not equal to 255 255 255 i will put 0 into the list. So when i look into the list, if there is 1 0 or 0 1 it means that border between transparent area and colored area or vice versa. But, how to know if that border is between transparent area in the middle of image and the image, and not between background and the image. Am i doing this correctly?
Here snippet of code.
Mat imgMask = Highgui.imread(imgfile);
double[] pixels = new double[3];
System.out.println("channel " + imgMask);
for(int x = 0; x < imgMask.cols(); x++) {
for(int y = 0; y < imgMask.rows(); y++) {
pixels = imgMask.get(y, x);
[Code] .....
View Replies
View Related
Apr 7, 2014
I have a popup that displays textual info and sometimes gets text input from the user. I'm using the following code:
JTextArea textArea = new JTextArea( getGameHistory( true, -2 ) );
JScrollPane scrollPane = new JScrollPane(textArea);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setFont(new Font("courier", Font.PLAIN, 12));
scrollPane.setPreferredSize( new Dimension( 30, 100 ) );
String input = JOptionPane.showInputDialog(null, scrollPane, "Fun Chess ",
JOptionPane.YES_NO_OPTION);
This shows a nice text area and an input field underneath it.The getGameHistory() method just returns a long string detailing the current game.Is there a way of just showing the text area without the input field underneath?Can the text area also be used for input instead?
View Replies
View Related
Sep 2, 2014
I've been having trouble with this code for about a week and I've finally got it down to one error. Here is the code:
import java.util.Scanner;
public class Triangle {
public static void main (String[] args) {
Scanner Console = new Scanner(System.in);
System.out.print("Please enter the three lengths of your Triangle: ");
double a = console.nextDouble();
[Code] ....
And here is the error:
Triangle.java:30: error: class, interface, or enum expected
} // End class
^
1 error
View Replies
View Related
Sep 26, 2014
how to put the output the the text area this is the code .
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package interns;
/**
*
* @author JosephP
*/
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
[Code]...
View Replies
View Related
Jul 17, 2014
I am doing exercises which has to do with the area of regular pentagon.
(Geometry: area of a regular polygon) A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is :
I have checked errata on their page and they did not list the type-o under the final result.
Errata link [URL] ....
their result is
Enter the number of sides: 5
Enter the side: 6.5
The area of the polygon is 74.69017017488385
and mine is Area of regular pentagon is 72.69017017488385
is it a code error?
import java.util.Scanner;
public class AreaOfAregularPolygon4_5 {
public static void main (String[] args){
//Initiate scanner and use the input
Scanner input = new Scanner (System.in);
System.out.println(" Enter the number of sides in polygon");
[Code] ....
View Replies
View Related
Mar 14, 2015
trying to tranfer content of a text area on one jframe to a text area in another
View Replies
View Related
Sep 1, 2014
import java.lang.Math;
public class triangle {
double area; double s;
public double findArea(double sideA, double sideB, double sideC);
{
s= 0.5 *(sideA + sideB + sideC);
area = Math.sqrt(s*(s-sideA)*(s-sideB)*(s-sideC));
[Code] ...
Errors I am getting:
Triangle.java:23: error: class, interface, or enum expected
import java.util.Scanner
^
Triangle.java:25: error: class, interface, or enum expected
public static void main(String[] args) {
[Code] ....
View Replies
View Related
Mar 22, 2015
I've been given a school assignment that reads, "Rewrite the main class Geometry so it takes in the dimensions for the triangle and ellipse as user inputs and create a Triangle and an Ellipse class. Use the appropriate variable types, constants, variable names and computational formulas.
Triangle class will have a computePerimeter and a computeArea methods Ellipse class will have a computeArea method Create Report class
• Create a method createReport that takes the values returned from Triangle and Ellipse and combines them in the following message and displays it. Format the values so that they have 2 decimals.
“The triangle has a perimeter of [perimeter] with an area of [area] while the ellipse has an area of [area]”
• Create a method switchReport that takes the original string from createReport and changes the message to display using the available methods in the String class
“The ellipse has an area of [area] while the triangle has an area of [area] with a perimeter of [perimeter]”"
I've run into a problem when creating the createReport method. Everytime i run it i get incorrect values for the perimeter and area (namely i get zero every time).
my code is as follows:
public class Triangle
{
public double base;
public double height;
public double hypotenuse;
private double tArea;
private double perimeter;
public Triangle()
{
base = 0;
height = 0;
hypotenuse = 0;
[code]....
For the triangle class and
public class Report {
Triangle tri2 = new Triangle();
Ellipse eli2 = new Ellipse();
public Report() {
}
public void createReport() {
System.out.println("The triangle has a perimeter of "+tri2.computePerimeter() +" with an area of " +tri2.computeTArea() +" while the ellipse has an area of " +eli2.computeEArea() );
}
for the report class.the Geometry class allows you to input values and if i skip the report and simply print the perimeter and area they are correct. However with the report class it simply gives me zeros.
View Replies
View Related