473,399 Members | 2,858 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,399 software developers and data experts.

Java Help Please!!!

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

(/Java)
Dec 4 '07 #1
1 1371
JosAH
11,448 Expert 8TB
Don't open multiple threads for one single problem; I close this thread and
answer your question in your other thread first thing in the (my) morning; it's late
overhere. And when you post a question think of a reasonable topic title. Your
current title is simply immature.

kind regards,

Jos
Dec 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: StealthMonkey | last post by:
Let me prefix this by saying that I know next to nothing about Java (so please try to keep explainations simple). I use PHP for my server-side web programming. Here is my dilemma: I need a...
3
by: Robert Bralic | last post by:
Hello, I writed small graphical editor for probabilystic networks in JAVA, but there was problem with making save file inJAVA. I thinked about it and I concluded that Save in JAVA is great...
19
by: Xandau | last post by:
hello all, i wotk with java every day but last time i have interested in C#. everything goes great except one thing... in java everything is a reference (except plain types) so i thought that...
6
by: gauravkhanna | last post by:
import java.io.*; class Automation1 implements Runnable { int iterationCount=0; Thread t; FileReader fr; //FileWriter fw; BufferedReader br; ...
7
by: hjc | last post by:
I am trying to write a program that tells the minium number of coins to give out for any amount of change from 1 cent to 99 cents. For example if the amount is 57 cents in the commmand prompt, the...
2
by: Knoxville | last post by:
Hello, I hope someone here can answer my question. To the point, I recently formatted my PC which is currently running on Windows ME (old, I know). I tried to install Java, both through offline and...
1
by: luthriaajay | last post by:
Has anyone used the 'importNode' and the 'replaceChild' methods of Interface Document and Node or adding 2 XML documents ? I need to add 2 XML documents in Java. DocumentOne -----------...
1
by: chetanankola | last post by:
BufferedImage image = null; image = ImageIO.read(new File("D:\testimage.jpg")); width=640; height=480; int rgbdata = new int; image.getRGB(0,0,width,height,rgbdata,0,width); bytes = new...
5
by: angelyn | last post by:
i'm having problem with these matter.. can you please give me exact translated code of this to java... <?php if ($_GET == "atr") { $handle =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.