cannot find 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<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 Tutorials/Questions & Answers:
cannot find symbol method nextchar()??cannot find symbol 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 Beginnerscannot find 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
Advertisements
cannot find symbol method append(String)cannot find symbol method append(String) what is the solution for
cannot find symbol method append(String)?
Hi,
Check tutorials:
How To Append String In Java?
Java - StringBuffer class in Java
Thanks
cannot find symbol method append(String)cannot find symbol method append(String) what is the solution for
cannot find symbol method append(String)?
Hi,
Check tutorials:
How To Append String In Java?
Java - StringBuffer class in Java
Thanks
JSP cannot find symbol error - JSP-ServletJSP
cannot find symbol 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 symbolJava error
cannot find symbol
In this section you will learn about "
cannot find symbol" in java. Java
cannot find symbol is a type of error occurs...
the variable in use its trying to refer, then it will give a error
cannot find
symbol Java error cannot find symbol “
cannot find symbol”.
The reason behind
cannot find symbol error... the java error
cannot find symbol. In this example a class name '
cannot find... “Java error
cannot find symbol”.ADS_TO_REPLACE_2
Java error cannot find symbol
Java error
cannot find symbol
The java error
cannot find symbol... error
cannot made
symbol. For this we have a class name
'
cannot find symbol cannot find symbol Scanner sc = new Scanner(system.in)cannot find symbol Scanner sc = new Scanner(system.in) In my one of the program in getting the error:
cannot find symbol Scanner sc = new Scanner(system.in)
How to resolve the error:
cannot find symbol Scanner sc = new Scanner
Error: Cannot find module 'jasmine-core'Error:
Cannot find module 'jasmine-core' Hi,
I am trying to make...:
karma start
Its throwing following error:
Error:
Cannot find module 'jasmine...;
^
Error:
Cannot find module 'jasmine-core'
at Function.Module.
Currency Symbol problemCurrency
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 cannot connect to database - JDBCcannot 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
The import javax.validation cannot be resolvedThe import javax.validation
cannot be resolved Hi,
I have a web application and due to missing maven dependency it is giving following error in Eclipse:
The import javax.validation
cannot be resolved.
What maven dependency
org.hibernate.validator cannot be resolved errororg.hibernate.validator
cannot be resolved error In Hibernate based application my application is giving following error:
org.hibernate.validator
cannot be resolved error
Program is not compiling due to this error.
How
GsonBuilder cannot be resolved to a typeGsonBuilder
cannot be resolved to a type Hi,
I am using GsonBuilder in my program and it is giving following compilation error:
GsonBuilder
cannot be resolved to a type
How to solve this?
What is the jar file for GsonBuilder
GsonBuilder cannot be resolved to a typeGsonBuilder
cannot be resolved to a type Hi,
I am using GsonBuilder in my program and it is giving following compilation error:
GsonBuilder
cannot be resolved to a type
How to solve this?
What is the jar file for GsonBuilder
GsonBuilder cannot be resolved to a typeGsonBuilder
cannot be resolved to a type Hi,
I am using GsonBuilder in my program and it is giving following compilation error:
GsonBuilder
cannot be resolved to a type
How to solve this?
What is the jar file for GsonBuilder
cannot display an arrayList in JSPcannot display an arrayList in JSP Hello,
My bean is called Zone, i got all Zones from sql Server with Hibernate.
in DAO.Class:
print("List zones = session.createQuery("FROM Zone").list();");
i want to send this List from
cannot do the additional operatorcannot 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 JavaFXcombobox
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
Cannot import XSSF in Apache POICannot import XSSF in Apache POI Hi,
I am trying to import the following library in code:
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
But the class is not present and
Cannot import XSSF in Apache POI.
How to solve
ls: cannot access >: No such file or directoryls:
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
Cannot assign an ArrayList to an empty ArrayListCannot 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 - Log4JJSP
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 removednull pointer exception
cannot be removed class list {
public...=0;
public int
q=0;
public static int i=0;
public arraylist() {
int...(int p,int
q){
int y=0;
for (y=0;y
}
else
arraylist.abcd[p
image cannot be saved - Java Beginnersimage
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