Write a program where you have to assign a class called
Circle
is to be defined as illustrated in the class diagram below. It contains two variables: radius
(of type double
) and color
(of type String
); and three methods: getRadius()
, getColor()
, and getArea()
.
Three instances of
Circle
s called c1
, c2
, and c3
shall then be constructed with their respective data members, as shown in the instance diagrams.
Source Code:
package crl;
class circle
{
double radius;
String colour;
circle(double r,String c)
{
radius=r;
colour=c;
}
double getRadius()
{
return radius;
}
String getColour()
{
return colour;
}
double getArea()
{
return 3.1416*radius*radius;
}
}
public class CRL
{
public static void main(String[] args)
{
circle c1=new circle(3.4,"Pink");
circle c2=new circle(1.1,"white");
circle c3=new circle(1.1,"blue");
System.out.println("Radius :"+c1.getRadius() + "Colour :"+c1.getColour()+"Area:"+c1.getArea());
System.out.println("Radius :"+c2.getRadius() + "Colour :"+c2.getColour()+"Area:"+c2.getArea());
System.out.println("Radius :"+c3.getRadius() + "Colour :"+c3.getColour()+"Area:"+c3.getArea());
}
}
package crl;
class circle
{
double radius;
String colour;
circle(double r,String c)
{
radius=r;
colour=c;
}
double getRadius()
{
return radius;
}
String getColour()
{
return colour;
}
double getArea()
{
return 3.1416*radius*radius;
}
}
public class CRL
{
public static void main(String[] args)
{
circle c1=new circle(3.4,"Pink");
circle c2=new circle(1.1,"white");
circle c3=new circle(1.1,"blue");
System.out.println("Radius :"+c1.getRadius() + "Colour :"+c1.getColour()+"Area:"+c1.getArea());
System.out.println("Radius :"+c2.getRadius() + "Colour :"+c2.getColour()+"Area:"+c2.getArea());
System.out.println("Radius :"+c3.getRadius() + "Colour :"+c3.getColour()+"Area:"+c3.getArea());
}
}
MAIN CLASS:
ReplyDeletepackage CircleCode;
public class Circle {
public static void main(String[] args) {
ColorCode C1;
ColorCode C2;
ColorCode C3;
C1=new ColorCode("Blue",2);
System.out.println("--------Properties of Circle C1-----");
C1.printInfo();
System.out.println("\n\n");
System.out.println("--------Properties of Circle C2-----");
C2=new ColorCode("Red",2);
C2.printInfo();
System.out.println("\n\n");
System.out.println("--------Properties of Circle C3-----");
C3=new ColorCode("Red",1);
C3.printInfo();
}
Helping Class :
package CircleCode;
public class ColorCode {
private double radius;
private String color;
public double pi=3.1416;
public ColorCode(){
radius=0;
color=new String();
}
public ColorCode(String color){
radius=0;
color=new String(color);
}
public ColorCode(String color,double radius){
this.color=color;
this.radius=radius;
}
public double getRadius(){
return radius;
}
public String getColor(){
return color;
}
public double getArea(){
return pi*radius*radius;
}
public void printInfo(){
System.out.println("Radius: "+getRadius());
System.out.println("Color: "+getColor());
System.out.println("Area: "+getArea());
}
}
}
package cir;
ReplyDeleteclass Circle
{
double radius;
String color;
Circle(double ra, String cl)
{
radius = ra;
color = cl;
}
double getRadius()
{
return radius;
}
String getColor()
{
return color;
}
double getArea()
{
return radius*radius*3.1416;
}
}
public class cir {
public static void main(String[] args)
{
Circle c1 =new Circle (1.2,"Red");
Circle c2 =new Circle (1.5,"Green");
Circle c3 =new Circle (2.5,"Blue");
System.out.println("Radius : " +c1.getRadius() + " Color : "+c1.getColor()+ " The area of circle is : "+c1.getArea());
System.out.println(" \n*************************************************************");
System.out.println("Radius : " +c2.getRadius() + " Color : "+c2.getColor()+ " The area of circle is : "+c2.getArea());
System.out.println(" \n**************************************************************");
System.out.println("Radius : " +c3.getRadius() + " Color : "+c3.getColor()+ " The area of circle is : "+c3.getArea());
System.out.println(" \n***************************************************************");
}
}
My Department :CSE
ReplyDeleteMy ID 201420656
package circle;
public class Circle
{
double radius;
String color;
Circle(double ahs, String sobuj)
{
radius = ahs;
color = sobuj;
}
double getRadius()
{
return radius;
}
String getColor()
{
return color;
}
double getArea()
{
return radius*radius*3.1416;
}
}
public class cir {
public static void main(String[] args)
{
Circle b1 =new Circle (2.2,"Red");
Circle b2 =new Circle (2.5,"Green");
Circle b3 =new Circle (3.5,"Blue");
System.out.println("Radius : " +b1.getRadius() + " Color : "+b1.getColor()+ " The area of circle is : "+b1.getArea());
System.out.println(" \n*************************************************************");
System.out.println("Radius : " +b2.getRadius() + " Color : "+b2.getColor()+ " The area of circle is : "+b2.getArea());
System.out.println(" \n**************************************************************");
System.out.println("Radius : " +b3.getRadius() + " Color : "+b3.getColor()+ " The area of circle is : "+b3.getArea());
System.out.println(" \n***************************************************************");
}
}
Sharmin Akter
ReplyDeleteMy Batch- 46th
My Department :CSE
My ID 201420769
package circle;
public class Circle
{
double radius;
String color;
Circle(double ahs, String sobuj)
{
radius = Sharmin;
color = Akter;
}
double getRadius()
{
return radius;
}
String getColor()
{
return color;
}
double getArea()
{
return radius*radius*3.1416;
}
}
public class cir {
public static void main(String[] args)
{
Circle p1 =new Circle (1.2,"Red");
Circle p2 =new Circle (1.5,"Green");
Circle p3 =new Circle (2.5,"Blue");
System.out.println("Radius : " +p1.getRadius() + " Color : "+p1.getColor()+ " The area of circle is : "+p1.getArea());
System.out.println(" \n*************************************************************");
System.out.println("Radius : " +p2.getRadius() + " Color : "+p2.getColor()+ " The area of circle is : "+p2.getArea());
System.out.println(" \n**************************************************************");
System.out.println("Radius : " +p3.getRadius() + " Color : "+p3.getColor()+ " The area of circle is : "+p3.getArea());
System.out.println(" \n***************************************************************");
}
}
Name-Main Uddin
ReplyDeleteID-201421090
Batch-46th
package Circle;
public class Circle
{
public static void main(String[] args)
{
GTR XX =new GTR (1.0,"Red");
GTR YY =new GTR (2.0,"Green");
GTR ZZ =new GTR (3.5,"Blue");
System.out.println("Radius-1 : " +XX.GTRedius() + " Color : "+XX.GTCol()+ " The area of circle is : "+XX.GTAr());
System.out.println(" \n");
System.out.println("Radius-2 : " +YY.GTRedius() + " Color : "+YY.GTCol()+ " The area of circle is : "+YY.GTAr());
System.out.println(" \n");
System.out.println("Radius-3 : " +ZZ.GTRedius() + " Color : "+ZZ.GTCol()+ " The area of circle is : "+ZZ.GTAr());
System.out.println(" \n");
}
}
class GTR
{
double R;
String C;
GTR(double Temp1, String Temp2)
{
R = Temp1;
C = Temp2;
}
double GTRedius()
{
return R;
}
String GTCol()
{
return C;
}
double GTAr()
{
return R*R*3.1416;
}
}
ID:201421066
ReplyDeleteBatch:46th
package homework;
class circle{
double radius;
String color;
circle( double rs, String cr)
{
radius=rs;
color=cr;
}
double getradius()
{
return radius;
}
String getcolor()
{
return color;
}
double getarea()
{
return radius*radius*3.141;
}
}
public class Homework {
public static void main(String[] args) {
circle c1= new circle (2.1,"red");
circle c2= new circle (2.5,"green");
circle c3= new circle (2.74,"blue");
System.out.println("Radius : "+c1.getradius() + " Color :"+c1.getcolor()+" Total Area :"+c1.getarea());
System.out.println("\n*******************************");
System.out.println("Radius :"+c2.getradius() + " Color :"+c2.getcolor()+" Total Area :"+c2.getarea());
System.out.println("\n*******************************");
System.out.println("Radius :"+c3.getradius() + " Color :"+c3.getcolor()+" Total Area :"+c3.getarea());
System.out.println("\n*******************************");
}
}
package Circle;
ReplyDeleteclass Cir
{
double radius;
String color;
Cir(double ra, String cl)
{
radius = ra;
color = cl;
}
double getRadius()
{
return radius;
}
String getColor()
{
return color;
}
double getArea()
{
return radius*radius*3.1416;
}
}
public class Circle {
public static void main(String[] args)
{
Cir c1 =new Cir (1.5,"Green");
Cir c2 =new Cir (1.4,"Pink");
Cir c3 =new Cir (2.4,"Black");
System.out.println("Radius : " +c1.getRadius() );
System.out.println("Color : "+c1.getColor());
System.out.println("The area of circle is : "+c1.getArea());
System.out.println();
System.out.println("Radius : " +c2.getRadius() );
System.out.println("Color : "+c2.getColor());
System.out.println("The area of circle is : "+c2.getArea());
System.out.println();
System.out.println("Radius : " +c3.getRadius() );
System.out.println("Color : "+c3.getColor());
System.out.println("The area of circle is : "+c3.getArea());
}
}
package Circle;
ReplyDeleteclass Cir
{
double radius;
String color;
Cir(double ra, String cl)
{
radius = ra;
color = cl;
}
double getRadius()
{
return radius;
}
String getColor()
{
return color;
}
double getArea()
{
return radius*radius*3.1416;
}
}
public class Circle {
public static void main(String[] args)
{
Cir c1 =new Cir (1.5,"Green");
Cir c2 =new Cir (1.4,"Pink");
Cir c3 =new Cir (2.4,"Black");
System.out.println("Radius : " +c1.getRadius() );
System.out.println("Color : "+c1.getColor());
System.out.println("The area of circle is : "+c1.getArea());
System.out.println();
System.out.println("Radius : " +c2.getRadius() );
System.out.println("Color : "+c2.getColor());
System.out.println("The area of circle is : "+c2.getArea());
System.out.println();
System.out.println("Radius : " +c3.getRadius() );
System.out.println("Color : "+c3.getColor());
System.out.println("The area of circle is : "+c3.getArea());
}
}
package crl;
ReplyDeleteclass circle
{
double radius;
String colour;
circle(double r,String c)
{
radius=r;
colour=c;
}
double getRadius()
{
return radius;
}
String getColour()
{
return colour;
}
double getArea()
{
return 3.1416*radius*radius;
}
}
public class CRL
{
public static void main(String[] args)
{
circle c1=new circle(3.4,"Pink");
circle c2=new circle(1.1,"white");
circle c3=new circle(1.1,"blue");
System.out.println("Radius :"+c1.getRadius() + "Colour :"+c1.getColour()+"Area:"+c1.getArea());
System.out.println("Radius :"+c2.getRadius() + "Colour :"+c2.getColour()+"Area:"+c2.getArea());
System.out.println("Radius :"+c3.getRadius() + "Colour :"+c3.getColour()+"Area:"+c3.getArea());
}
}