question archive Shapes You are working on a graphical app, which includes multiple different shapes

Shapes You are working on a graphical app, which includes multiple different shapes

Subject:Computer SciencePrice:4.87 Bought7

  1. Shapes

You are working on a graphical app, which includes multiple different shapes.

The given code declares a base Shape class with an abstract area() method and a width attribute.

MAke a two Shape subclasses, Square and Circle, which initialize the width attribute using their constructor, and define their area() methods.

The area() for the Square class should output the area of the square (the square of the width), while for the Circle, it should output the area of the given circle (PI*width*width).

The code in main creates two objects with the given user input and calls the area() methods.

Sample Input:

5

2

Sample Output:

25

12.566370614359172

The area of the square is 5*5=25, while the area of the circle is PI*2*2=12.566370614359172

Use the Math.PI constant for the area calculation of the circle.

  1. Binary Converter

The binary numeric system uses only two digits: 0 and 1. Computers operate in binary, meaning they store data and perform calculations using only zeros and ones.

Make a program to convert integer numbers to their binary representation.

Make a Converter class with a static toBinary() method, which returns the binary version of its argument.

The code in main takes a number as input and calls the corresponding static method. Make sure the code works as expected.

Sample Input:

42

Sample Output:

101010

You can use the following code to convert a number to binary:

String binary="";

while(num > 0) {

binary = (num%2)+binary;

num /= 2;

}

JAVA

The code above uses a loop to convert num to binary and stores the result in the binary String.

 

Option 1

Low Cost Option
Download this past answer in few clicks

4.87 USD

PURCHASE SOLUTION

Option 2

Custom new solution created by our subject matter experts

GET A QUOTE

rated 5 stars

Purchased 7 times

Completion Status 100%