cannot find symbol 1 Answer(s) 3 years and 4 months ago
Posted in : Java Beginners
public class Areatest { public static void main(String[]args) { Figure[]figures={new Triangle(2.0,3.0,3.0),new Rectangle(4.0,6.0),new Square(5.0)}; for(int i=0;i<figures.length;i++) { System.out.println("Area of "+figures[i]+" is "+figures[i].getArea()); } } } abstract class Figure { public abstract double getArea(); } class Triangle extends Figure { double la,lb,lc; Triangle(double la,double lb,double lc) { this.la=la;this.lb=lb;this.lc=lc; } public String toString() { return "Triangle: sides are "+la+", "+lb+"& "+lc+":"; } public double getArea() { double s=(la+lb+lc)/2; return Math.sqrt(s*(s-la)*(s-lb)*(s-lc)); } } class Rectangle extends Figure { double width,height; Rectangle(double width,double height) { this.width=width;this.height=height; } public String toString() { return "Rectangle: width= "+width+", height="+height; } public double getArea() { return width*height; } } class Square extends Figure { Square(double width) { this.width=width; } public String toString() { return "Square: width= "+width; } public double getArea() { return width*width; } }
View Answers
January 14, 2010 at 10:03 AM
Hi Friend,
You haven't define variable width in Square class.
Here is your modified code:
public class Areatest{ public static void main(String[]args){ Figure[]figures={new Triangle(2.0,3.0,3.0),new Rectangle(4.0,6.0),new Square(5.0)}; for(int i=0;i<figures.length;i++) { System.out.println("Area of "+figures[i]+" is "+figures[i].getArea()); } } } abstract class Figure { public abstract double getArea(); } class Triangle extends Figure { double la,lb,lc; Triangle(double la,double lb,double lc) { this.la=la;this.lb=lb;this.lc=lc; } public String toString() { return "Triangle: sides are "+la+", "+lb+"& "+lc+":"; } public double getArea() { double s=(la+lb+lc)/2; return Math.sqrt(s*(s-la)*(s-lb)*(s-lc)); } } class Rectangle extends Figure { double width,height; Rectangle(double width,double height) { this.width=width;this.height=height; } public String toString() { return "Rectangle: width= "+width+", height="+height; } public double getArea() { return width*height; } } class Square extends Figure { double width; Square(double width){ this.width=width; } public String toString() { return "Square: width= "+width; } public double getArea() { return width*width; } }
Thanks
Related Pages:
cannot find symbol method nextchar()?? cannotfindsymbol method nextchar()?? import java.util.Scanner;
public class Calc5{
public static void main(String args[]){
Scanner obj = new Scanner(System.in);
System.out.println("please enter
cannot find symbol - Java Beginners cannotfind symbol public class Areatest
{ public static void main(String[]args)
{
Figure[]figures={new Triangle(2.0,3.0,3.0),new Rectangle(4.0,6.0),new Square(5.0)};
for(int i=0;i
JSP cannot find symbol error - JSP-Servlet
JSP cannotfindsymbol error Suppose-- we created 'a.jsp' in which we make a database connection...
how to retrieve 'new' here...
If I want to access the 'new' string within the form what should i do???  
Java error cannot find symbol
“cannotfind symbol”.
The reason behind cannotfindsymbol error... the java error cannotfindsymbol. In this example a class name 'cannotfind.../src/
Cannotfindsymbol.java:11: cannotfindsymbolsymbol: variable z
Java error cannot find symbol
Java error cannotfindsymbol
The java error cannotfindsymbol occurred when a Compiler... a class name
'cannotfindsymbol'. Inside the main method we have initialized
cannot find symbol class array queue--plzz somebody help.. cannotfindsymbol class array queue--plzz somebody help.. import java.util.*;
public class Test {
public static void main(String[] args)
{
ArrayQueue<String> q = new ArrayQueue<String>(6);
System.out.println
Cannot find tag library descriptor Cannotfind tag library descriptor Cannotfind tag library descriptor...? How to resolve in struts in eclipse
Cannot find FacesContext exception - Java Server Faces Questions Cannotfind FacesContext exception Hi all,
I am into an web application,where we are using Richfaces. Now, When I try to create a new Jsp page using taglibs[faces, html], getting 'Cannotfind FacesContext' exception.
What
cannot find java.exe error while opening netbean5.5 - IDE Questions cannotfind java.exe error while opening netbean5.5 HI,
1)i am working netbean5.5 tool.I got the error of cannotfind c:\programfiles\java\jdk1.6.0_02. (while opening netbean5.5 shortcut in desktop) .
my system jdk path
Currency Symbol problem
Currency Symbol problem Hi All,
My Server side code... Symbol is: PEN
Local is: en
Local is: es_PA, Currency Symbol is: PAB
Local is: sr_BA, Currency Symbol is: BAM
Local is: mk
Local is: es_GT, Currency Symbol
Java 2 micro editionJ
javax.microedition.io does not exist
cannotfindsymbolcannotfindsymbolcannotfindsymbol class Form
cannotfindsymbol class Display
cannotfindsymbol class TextField
cannotfindsymbol class Ticker
cannotfindsymbol class
Java error cannot read
Java error cannot read
The Java error cannot read occurred when a programmer do... a method .get Year (
).On execution the code show you an error Java Error cannot
Symbol Substitution Symbol Substitution
In this example , we are going... values which
will converted it into symbol. For this we just convert
cannot connect to database - JDBC cannot connect to database Iam using eclipse in my system ,when connecting the database mysql version 5.0 to the eclipse iam getting an error as ""Creating connection to mysql has encountered a problem.Could not connect to mysql
cannot do the additional operator cannot do the additional operator i got problem with additional and multiplication operator...please anyone help me
<html>
<head>
<title>Simple Calculator</title>
<script language = "JavaScript
combobox cannot be resolved in JavaFX
combobox cannot be resolved in JavaFX I want to design one application with a combobox containing items. and while selecting i want to give user autocomplete suggestion. but while doing this combobox is not getting resolved. i
equal symbol expected in jsp - JSP-Servlet
equal symbol expected in jsp Hi frndz i am using following code to upload a file.
<%
Connection con=null;
PreparedStatement pstatement... error
org.apache.jasper.JasperException: /upload_page.jsp(2,26) equal symbol
How to make a loading symbol
How to make a loading symbol
Learn here to create your own loading symbol that show
the loading process in the website.
New File: Take a new document.
Draw a Circle: Draw a circle with this "f20b27" color
by using
How to design a question message symbol
How to design a question message symbol
Let's see how to make a question message symbol,
you can make it by this example.
Draw a circle....
Your will get it.
Inset symbol: Choose Horizontal type tool (T
How to insert a symbol on the stone
How to insert a symbol on the stone
If you are not able to insert a symbol on the any
object, you should come to this example to learn... symbol shape.
It is your done here.
Look
java.lang.IllegalArgumentException: node to traverse cannot be null!
java.lang.IllegalArgumentException: node to traverse cannot be null! Hi,
I am new to Hibernate.
I am facing the problem
java.lang.IllegalArgumentException: node to traverse cannot be null!
while updating a row.
The code
ls: cannot access >: No such file or directory
ls: cannot access >: No such file or directory import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Example...: cannot access >: No such file or directory error is displayed .No f.txt
errors
errors i am getting an error saying cannotfindsymbol class string.how do i rectify
how to write greater than symbol in a file using java
how to write greater than symbol in a file using java Hello
I want to write < and > symbol in a file but its coming like > and <
Please... the greater than and less than symbol is coming as & gt and & lt
Cannot assign an ArrayList to an empty ArrayList Cannot assign an ArrayList to an empty ArrayList I have a java file, in which a method returns an ArrayList. This ArrayList is supposed to contain all the Student object which are in X year.
StudentsManager.java
public
JSP cannot log to FileAppender - Log4J
JSP cannot log to FileAppender Hi,
Thank you for your attention :)
I have a webapp running on Tomcat 5.5, which does all its logging using Log4j.
At the moment, it logs fine to console when run from class main method
null pointer exception cannot be removed
null pointer exception cannot be removed class list {
public int integer;
public String elem;
public list next;
private Exception nothing;
public int r;
public list() {
this(null,null,0
image cannot be saved - Java Beginners
image cannot be saved In the following program when we click on the menu item import, we can show any image on the panel but when we click on save the image is not drawn on the desired location.......please check the following
JAVA
*;
^
InsertServlet.java:6: cannotfindsymbolsymbol: class HttpServlet
public class...{
^
InsertServlet.java:7: cannotfindsymbolsymbol : class HttpServletRequest
location... {
^
InsertServlet.java:7: cannotfindsymbolsymbol : class HttpServletResponse
location
cannot declare variable inside @interface or @protocol cannot declare variable inside @interface or @protocol When i declare variable inside the interface, it always send an error saying "cannot declare variable inside @interface or @protocol". Can anyone please tell me why
cannot open .jar files by double click cannot open .jar files by double click I'm having a problem i create a .jar file in net beans and yesterday it work right b y and double click but i... the error as " main class cannot be found " plz help i'm stucked now
still i have
find the factorial find the factorial how to find the factorial through the while loop?
class FindFactorial
{
public static void main(String[] args)
{
int value = 5, factorial = 1, temp = value;
while
find and substring find and substring **import java.io.BufferedReader;
import... BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter find...){
}
}
public void findreplace(String find, String replace
Cannot run Struts 2 on IntelliJ Project - Struts Cannot run Struts 2 on IntelliJ Project I have been trying to run Struts 2 on IntelliJ IDEA for the past two weeks, can anyone help with basic example?
starting from struts 2 configuration and installation.
its very urgent
arrays,why we cannot use this statement
arrays,why we cannot use this statement import java.util.*;
class Dash{
public static void main(String args[]){
int x0=100;
int[] x1=new int[3];
int[][] x2=new int[3][3];
int[][][] x3
arrays,why we cannot use this statement
arrays,why we cannot use this statement import java.util.*;
class Dash{
public static void main(String args[]){
int x0=100;
int[] x1=new int[3];
int[][] x2=new int[3][3];
int[][][] x3
servlet - JSP-Servlet
*;
^
Avanthi.java:7: cannotfindsymbolsymbol: class HttpServlet
public class Avanthi extends...{
^
Avanthi.java:39: cannotfindsymbolsymbol : class ServletRequest
location: class...: cannotfindsymbolsymbol : class ServletResponse
location: class Avanthi
find and replace in java find and replace in java Need 'find and replace' function in Java to find special keyword in XMl such as @,#,!,%..and replace with their corresponding entities
error in java progran at run time - Java Beginners
)
^
FirstServlet.java:6: cannotfindsymbolsymbol : class ServletResponse
location... javax.Servlet does not exist
import javax.Servlet.*;
^
FirstServlet.java:4: cannotfind... GenericServlet
^
FirstServlet.java:6: cannotfind