11 Replies - 848 Views - Last Post: 25 February 2010 - 06:55 PM Rate Topic: -----

#1 Guest_Maj*


Reputation:

Java Assignment

Posted 25 February 2010 - 09:50 AM

I have an assignment in java

the question said

Make a super class name Circle that has two methods used in circles, Area and Circumferences. To get the Area of the circle this is the formula: a=pir^2, and to get the Circumferences of the Circle this is the formula: a=2pir. Make another class which the subclass of the class Circle. Name it as Square which will do the operations for a square shape. This class has three methods: Area, Volume and Perimeter. To get the Area of square this is the formula: p=4side. In the main class, get the radius of two circles and show its Area and Circumferences, and get the side of one square, then show the Area Volume and Perimeter of the square. Radius and Side values are taken from the user.

I'll be appreciating so much for help in writing the program.

Regards
MAj

Is This A Good Question/Topic? 0

Replies To: Java Assignment

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10364
  • View blog
  • Posts: 38,372
  • Joined: 27-December 08

Re: Java Assignment

Posted 25 February 2010 - 09:55 AM

We would be more than happy to help if you could show us your good faith efforts. :)
Was This Post Helpful? 0
  • +
  • -

#3 Ghlavac  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 519
  • Joined: 14-January 09

Re: Java Assignment

Posted 25 February 2010 - 09:55 AM

Seeing as you already seem to have the equations for what you need to get. I would start with constructing objects for the circle/square.

Then post some of what you get from that her for more help.
Was This Post Helpful? 0
  • +
  • -

#4 Simple_Condolences  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 138
  • Joined: 10-January 10

Re: Java Assignment

Posted 25 February 2010 - 11:40 AM

For Pi, try using MATH.pi.

Just an idea. Feel free to come back and ask for help once you've gotten a good start!

- Zach
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Java Assignment

Posted 25 February 2010 - 05:38 PM

View PostMaj, on 25 February 2010 - 10:50 AM, said:

I'll be appreciating so much for help in writing the program.

We will be glad to help you fix the problem in the code YOU wrote
Was This Post Helpful? 0
  • +
  • -

#6 Guest_Maj*


Reputation:

Re: Java Assignment

Posted 25 February 2010 - 05:59 PM

bros thank u 4 the interest of help. i have done this subject last year and i've forget everything about it except showing the output so I'll appreciate so much of helping me to write this program. Other thing this is 4 my friend .

Regards
Maj
Was This Post Helpful? 0

#7 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10364
  • View blog
  • Posts: 38,372
  • Joined: 27-December 08

Re: Java Assignment

Posted 25 February 2010 - 06:06 PM

We still will not do your friend's homework. If you or he needs help, we need to see a good faith effort before helping you. If you want to pick up some Java, check out our tutorials section. There are a a few good beginner tutorials there, like NeoTifa's.
Was This Post Helpful? 0
  • +
  • -

#8 Guest_Maj*


Reputation:

Re: Java Assignment

Posted 25 February 2010 - 06:08 PM

other thing this is my trial

import java.io.*;
public class circle
{
public static void main(String[]args) throws Exception
{
double a,b,c,d,e,f,g,h,i,j;

BufferedReader z=new BufferedReader(new InputStreamReader (System.in));
System.out.println("enter radius for circle no.1:");
a=Double.parseDouble(z.readLine());
System.out.println("enter radius for circle no.2:");
b=Double.parseDouble(z.readLine());
System.out.println("enter sides for the square: ");
c=Double.parseDouble(z.readLine());

set2 c1= new set2(a);
set2 c2=new set2(B);
squ s=new squ(b,c);

d=c1.area();
e=c2.area();
f=c1.circumference();
g=c2.circumference();
h=s.area();
i=s.volume();
j=s.perimeter();
System.out.println("area no.1:"+d);
System.out.println("area no.2:"+e);
System.out.println("circumference no1:"+f);
System.out.println("circumference no1:"+g);
System.out.println("Square area:"+h);
System.out.println("Volume:"+i);
System.out.println("perimeter:"+j);
}
}





import java.io.*;
public class set2
{
double r;
double pi=3.1416;
public set2(double c)
{
}
public void Circle (double x)
{
r=x;
}
public double area()
{
return (pi*(r*r));
}
public double circumference()
{
return (2*pi*r);
}
}





import java.io.*;
public class squ extends set2
{
double side;
public squ (double d, double e)
{
super(d);
side=e;
}
public double area()
{
return (side*side);
}
public double volume()
{
return (side * side * side);
}
public double perimeter()
{
return (4*side);
}
}

plz advice
Was This Post Helpful? 0

#9 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10364
  • View blog
  • Posts: 38,372
  • Joined: 27-December 08

Re: Java Assignment

Posted 25 February 2010 - 06:12 PM

Please, :code:
Also, please specifically describe the errors you are encountering.
Was This Post Helpful? 0
  • +
  • -

#10 Guest_Maj*


Reputation:

Re: Java Assignment

Posted 25 February 2010 - 06:30 PM

 import java.io.*;
public class circle
{
public static void main(String[]args) throws Exception
{
double a,b,c,d,e,f,g,h,i,j;

BufferedReader z=new BufferedReader(new InputStreamReader (System.in));
System.out.println("enter radius for circle no.1:");
a=Double.parseDouble(z.readLine());
System.out.println("enter radius for circle no.2:");
b=Double.parseDouble(z.readLine());
System.out.println("enter sides for the square: ");
c=Double.parseDouble(z.readLine());

set2 c1= new set2(a);
set2 c2=new set2(B)/>;
squ s=new squ(b,c);

d=c1.area();
e=c2.area();
f=c1.circumference();
g=c2.circumference();
h=s.area();
i=s.volume();
j=s.perimeter();
System.out.println("area no.1:"+d);
System.out.println("area no.2:"+e);
System.out.println("circumference no1:"+f);
System.out.println("circumference no1:"+g);
System.out.println("Square area:"+h);
System.out.println("Volume:"+i);
System.out.println("perimeter:"+j);
}
}





import java.io.*;
public class set2
{
double r;
double pi=3.1416;
public set2(double c)
{
}
public void Circle (double x)
{
             r=x;
}
public double area()
{
return (pi*(r*r));
}
public double circumference()
{
return (2*pi*r);
}
}





import java.io.*;
public class squ extends set2
          {
double side;
public squ (double d, double e)
{
super(d);
side=e;
}
public double area()
{
return (side*side);
}
public double volume()
{
return (side * side * side);
}
public double perimeter()
{
return (4*side);
}
}


Was This Post Helpful? 0

#11 Guest_Maj*


Reputation:

Re: Java Assignment

Posted 25 February 2010 - 06:31 PM

hope to help me to find errors
Was This Post Helpful? -1

#12 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Java Assignment

Posted 25 February 2010 - 06:55 PM

What is the use of a constructor who receives an argument and does nothing with it ?

public set2(double c) 
{ 
} 


you probably want
public set2(double c) 
{ 
  r = c;
} 



If you used meningful variable names it would be a lot easier
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1