Java Assignment
Page 1 of 111 Replies  876 Views  Last Post: 25 February 2010  06:55 PM
#1 Guest_Maj*
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
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
Replies To: Java Assignment
#2
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.
#3
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.
Then post some of what you get from that her for more help.
#4
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
Just an idea. Feel free to come back and ask for help once you've gotten a good start!
 Zach
#5
Re: Java Assignment
Posted 25 February 2010  05:38 PM
#6 Guest_Maj*
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
Regards
Maj
#7
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.
#8 Guest_Maj*
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(;
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
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(;
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
#9
Re: Java Assignment
Posted 25 February 2010  06:12 PM
Please,
Also, please specifically describe the errors you are encountering.
Also, please specifically describe the errors you are encountering.
#10 Guest_Maj*
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); } }
#11 Guest_Maj*
Re: Java Assignment
Posted 25 February 2010  06:31 PM
hope to help me to find errors
#12
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 ?
you probably want
If you used meningful variable names it would be a lot easier
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
Page 1 of 1
