Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package input;
- /**
- *
- * @author MPA3
- */
- // Coded By Fakhrurazi <3
- import java.util.Scanner;
- public class Input {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- final double pi = 3.142;
- int graphHeight, graphWidth, angle, aspectedGraphHeight, row, column, x, y, angleStep;
- int radius;
- int ans;
- //String s = "";
- System.out.println("|Area of Circle Calculator|");
- System.out.println("Choose Mode: \n1.Diameter\n2.Radius");
- Scanner input = new Scanner(System.in);
- int sel = input.nextInt();
- if(sel == 1){
- System.out.println("Insert value in Diameter: ");
- ans = input.nextInt();
- // ans = (diameter/2) * (daimeter/2);
- System.out.println("The area of circle is: " + (pi * (ans/2) * (ans/2) ));
- }else if(sel == 2){
- System.out.println("Insert value in Radius: ");
- ans = input.nextInt();
- //radius = radius2;
- System.out.println("The area of circle is: " + (pi * ans * ans));
- }else {
- System.out.println("Wrong Selection. Exiting...");
- }
- char[][] circle = new char [150][150];
- // Scanner in = new Scanner(System.in);
- System.out.print("\n\n\t\t\t###### Draw circle #######\n");
- //System.out.print( "\n\t\tEnter graph Height: ");
- //graphHeight = in.nextInt();
- graphHeight = 20;
- //System.out.print( "\t\tEnter graph Width: ");
- //graphWidth = in.nextInt();
- graphWidth = 20;
- System.out.print( "\t\tRadius of circle: ");
- radius = input.nextInt();
- //radius = ans;
- //converting degree to radian by multiplying with pi/180
- angle = (int)(360 * Math.PI/180);
- //.5 is for precision
- aspectedGraphHeight = (int)(graphHeight/2.0);
- // define graphpaper
- for(row=0; row<=aspectedGraphHeight; row++)
- {
- for(column=0; column<=graphWidth; column++)
- {
- circle[row][column]=' ';
- }
- }
- //horizontal axis
- for(column = 0; column <= graphWidth; column++)
- {
- row = aspectedGraphHeight / 2;
- circle[row][column] = '-';
- }
- //vertical axis
- for(row = 0; row <= aspectedGraphHeight; row++)
- {
- column = graphWidth / 2;
- circle[row][column] = '|';
- }
- //points of circle
- for (angle = 0; angle <= 360; angle += 1)
- {
- x = (int)(radius * Math.cos(angle));
- y = (int)(radius * Math.sin(angle));
- row = (aspectedGraphHeight/2 - y/2);
- // y is divided by scaling factor 2 for aspected ratio of characters in terminal
- column = graphWidth/2 + x;
- circle[row][column] = '.';
- }
- //print circle
- for(row = 0; row<=aspectedGraphHeight; row++)
- {
- for(column = 0; column<=graphWidth; column++)
- System.out.print(circle[row][column]);
- System.out.println(" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement