473,322 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

quick question!!

Hi,
when I go to compile my program it throws up an error saying:

Orange.java:5: <identifier> expected
y.area();


Is there a common error why this happens??
Dec 4 '07 #1
2 1171
JosAH
11,448 Expert 8TB
Hi,
when I go to compile my program it throws up an error saying:

Orange.java:5: <identifier> expected
y.area();


Is there a common error why this happens??
Sure, most likely you've put statements outside of a method or an initialization
block but noone can tell for sure because your question was very vague and the
necessary information you gave was less than vague and incomplete as well.

Always supply the complete error diagnostic message (copy/paste) and the
relevant lines of code that caused the error diagnostic. We are not going to guess
for you.

kind regards,

Jos
Dec 4 '07 #2
The question is below and it is the only one I cant for a project due tomarrow.

Question.
Write a class called shapes that accepts two variables into its constructor called a and b. Along with the getter and setter methods required, write a method called toPrinter() to output the coordinates of the shape in the following format: [a, b].
Next write a class called orange that is a child class of shapes. This time the constructor accepts in a, b (centre of the orange), and a radius. Override the toPrinter() method in the orange class to include outputting the radius, as well as a and b. Write a method to get the area of the orange. Include any relevant classes to run and test the application.

I can do the first part but not the second.

This is what I have so far.

Code: (Java)
class Shapes
{
public static void main(String[] args)
{

Shapes x = new Shapes(5,6);

x.toPrinter();

}

protected double a;
protected double b;



public Shapes(double a, double b)
{
this.a = a;
this.b = b;
}


public double geta()
{
return a;
}

public double getb()
{
return b;
}



protected void seta(double ia)
{
a = ia;
}

protected void setb(double ib)
{
b = ib;
}




void toPrinter()
{
System.out.println("The coordinates are [" + a +","+ b + "]");
}


}


class Orange extends Shapes
{
Orange y = new Orange(a,b,7);

y.area();
y.toPrinter();


private double radius;
private double area;

public Orange (double a, double b, double radius)

{
super(a,b);
this.radius = radius;
}

void area()
{
this.area = (3.14) *(radius) * (radius);
}

void toPrinter()
{
System.out.println("The coordinates are [" + a +","+ b + "]");
System.out.println("The radius is " + radius);
System.out.println("The area is " + area);
}



public double getradius()
{
return radius;
}

public double getarea()
{
return area;
}



protected void setradius(double iradius)
{
radius = iradius;
}

protected void setarea(double iarea)
{
area = iarea;
}


}


// the orange class is on a seperate java file. when i go to compile it, an error shows up saying:

Orange.java:5: <identifier> expected
y.area();

Orange.java:6: <identifier> expected
y.toPrinter();
^
2 errors
Dec 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jack | last post by:
I pulled this script out of a larger one to test, and I can't figure it out. If I keep this script in the same directory as the files I want to read, it works fine, but if I move the script out of...
10
by: Snake | last post by:
Hello guys, I have a quick question about pointers. When I say int *p; *p = 40; cout << *p; why does that produce and error message(something about fault address)? Isnt that I created a...
30
by: Christopher Benson-Manica | last post by:
Given the following: char s="Hello, world\n!"; Are all the following guaranteed to produce the same output? printf( "%s", s ); fprintf( stdout, "%s", s ); fwrite( s, sizeof(char),...
5
by: tariq | last post by:
Hi, got a quick question on al.exe i have an assembly say library.dll without any strong name i have a sn pair say org.snk how do i sign library.dll with org.snk using al? tx -T
1
by: Mike | last post by:
Hi, I am using an enum to map to certain columns instead of using the string name. When I use the enum as the indexer in a datarow it forces me to cast it into an int. Shouldn't this be...
6
by: z_learning_tester | last post by:
Quick question- What happens if you have a private class with a public static method? Can you still say the following? Lets say you are making this call from another class, say class2... int...
3
by: craig | last post by:
Quick question for the experts... Whenever I set the Image property of a PictureBox on one of my forms to a PNG graphic file on my hard drive, I get the following runtime error when I try to run...
2
by: Rudy | last post by:
Hello all! Have a quick question on drop down list. Need to make a year ddl, 1900 to 1987. Is there a quick way to do this. I'm not binding this, just loading it in the items collection. ...
3
by: Brian | last post by:
A quick question here - What can be achieved in IL which is not possible in C# ? o Creation of an ArrayList o Creation of a Dictionary o Creation of a two dimensional array...
1
by: JustTrev | last post by:
Hi I have a quick question. I'm studying how XML works in sq server 2005, and I've hit the following code online that I can't completely understand (see below code). I know what it does, how it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.