Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert these two C# code to Java code File one using System; public static class Lab3 { public static void Main() {double inpRadius; // create

Convert these two C# code to Java code

File one

using System;

public static class Lab3

{

public static void Main()

{double inpRadius;

// create a circle object with no arg constructor

Circle cir1 = new Circle();

// create a circle object with one arg constructor

Circle cir2 = new Circle(10);

// print out the area of the circles

Console.WriteLine("Circle 1 has radius {0} and area {1:F2}",

cir1.Radius, cir1.GetArea);

Console.WriteLine("Circle 2 has radius {0} and area {1:F2}",

cir2.Radius, cir2.GetArea());

//prompt the user for a radius

do

{

Console.Write("Enter a positive radius => ");

inpRadius = Convert.ToDouble(Console.ReadLine());

} while (inpRadius < 0);

cir1.Radius = inpRadius;

// print out the area of the circles

Console.WriteLine("Circle 1 has radius {0} and area {1:F2}",

cir1.Radius, cir1.GetArea());

Console.WriteLine("Circle 2 has radius {0} and area {1:F2}",

cir2.Radius, cir2.GetArea());

//add circles

if(cir1 > cir2)

Console.WriteLine("Circle 1, with radius {0} is bigger the Circle 2 with radius {1}", cir1.Radius, cir2.Radius)

else

Console.WriteLine("Circle 1, with radius {0} is not bigger the Circle 2 with radius {1}", cir1.Radius, cir2.Radius)

Console.ReadLine();

}

}

File two

// Code File Circle

using System;

public class Circle

{

private double radius;

private const double PI = 3.14159;

// no argument Constructor

public Circle()

{

radius = 0

}

// one argument Constructor

public Circle(double rad)

{

// make sure the parameter is not negative

if (rad < 0)

radius = 0;

else

radius = rad;

}

// Radius Property

public double Radius

{

// return the private data value on

get

{

return radius;

}

// make sure the implicit parameter is not negative on set

set

{

if (value < 0)

radius = 0;

else

radius = value;

}

}

// GetArea Method

public double GetArea()

{

double area;

// compute the area = radius^2 * PI

area = radius * radius * PI;

return area;

}

//overloaded > operator to compare circles

public static bool operator>(Circle circle1, Circle circle2) {

if(circle1.Radius > circle2.Radius)

return true;

return false;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

What is transfer pricing and how it is calculated?

Answered: 1 week ago