Sie sind auf Seite 1von 9

import java.util.

*;

public class Anything {

public static void main(String args[]) throws Exception


{

Scanner input = new Scanner(System.in);

Scanner scanner = new Scanner(System.in);

System.out.print(" enter your name: " );

String name = scanner.next();

System.out.println(" Hiii " + name + " what do you want ? ");

new java.util.Timer().schedule(

new java.util.TimerTask() {

@Override

public void run() {

System.out.println(" Here's a tip ");


System.out.println("if you want to calculate area type area ");
System.out.println("if you want to convert from decimal to binary or from binary to
decimal type convert (we can also convert to hexadecimal)" );
System.out.println( " type stop to exict the program " );

},

2500
);
int i =0;

do{

System.out.println( name + "... area or convert ? ");

String enter = input.next();

String convert;

String area;

String stop;

if(enter.equals("area")){

int a=0;

do{

System.out.println(" okay " + name + " area of what shape do you want
to calculate (for now i can only calculate 4 areas) ");

String AREA = input.next();

String triangle;

String square;

String circle;

String rectangle;
if (AREA.equals("triangle")){

System.out.print( " enter the base of the triangle = " );

double base = input.nextDouble();

System.out.print( " enter the height of the


triangle = " );

double height = input.nextDouble();

double areaa = (base * height) / 2;

System.out.print( " the area of this


triangle ( of height =" + height + "and a base=" + base +" ) is : " +
areaa);
}

else if (AREA.equals("square")){

System.out.print( " enter the side of the square =


" );

double side = input.nextDouble();

double areac = side * side;

System.out.print( " the area of this square (of


side = " + side + " ) is : " + areac);
}

else if (AREA.equals("circle")){

double radius;
double areab;

System.out.print( " enter the radius = ");

radius = input.nextDouble();

areab = 3.14 * radius * radius;

System.out.print( " the area of this circle (of radius = " + radius
+ " ) is : " + areab);}

else if (AREA.equals("rectangle")){

System.out.print( " enter the length of the rectangle =


" );

double length = input.nextDouble();

System.out.print( " enter the width of the


rectangle = " );

double width = input.nextDouble();

double aread = length * width;

System.out.print( " the area of this


rectangle(of width = " + width + " and length= " + length + " ) is : " +
aread );
}

else {

System.out.println( " sorry, we can't calculate " + AREA + " not yet ..." );}
System.out.println(" do you want to calculate area of any thing else ? " );

System.out.print ( " enter y for yes and n for no " );

String chiocea =input.next();

String y;

String n;

if(chiocea.equals("n")){break;}

else if(chiocea.equals("y")){continue;}

else { System.out.print( " sorry we said y or n not " + chiocea );}

a++;

}while(a<100);

else if(enter.equals("convert")){

int b=0;

do{

System.out.println( " okay " + name + " type decimal to convert to decimal and
type binary to convert to binary and type HEX to convert to hexadecimal");

String CONVERT = input.next();

String decimal;

String binary;
String HEX;
if(CONVERT.equals("decimal")){

Scanner sc = new Scanner(System.in);

System.out.println("Enter a binary number ::");

String Binary = sc.next();

int Decimal = Integer.parseInt(Binary, 2);

System.out.println("Decimal value of the given binary


number is ::"+Decimal);

else if (CONVERT.equals("binary")){

Scanner in = new Scanner(System.in);

Stack<Integer> stack = new Stack<Integer>();

System.out.println("Enter decimal number: ");

int num = in.nextInt();

while (num != 0)
{

int d = num % 2;

stack.push(d);

num /= 2;
}

System.out.print("\nBinary representation is:");

while (!(stack.isEmpty() ))
{
System.out.print(stack.pop());
}

System.out.println(); }

else if (CONVERT.equals("HEX")){ Scanner sareeni = new Scanner( System.in );

System.out.print("Enter a decimal number : ");

int num =sareeni.nextInt();

int rem;

String str2="";

char hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

while(num>0)
{

rem=num%16;

str2=hex[rem]+str2;

num=num/16;
}

System.out.println("your number in hexadecimal ::: "+str2);


}

else {
System.out.println( " sorry, we can't convert " + CONVERT);}

System.out.println( " do you want to convert any thing else ? ");

System.out.print (" enter Y for yes and N for no ");

String chioceb =input.next();

String Y;

String N;
if(chioceb.equals("N")){break;}

else if(chioceb.equals("Y")){continue;}

else { System.out.print(" sorry we said Y or N not " + chioceb );}

b++;

}while(b<100);

else if(enter.equals("stop")){
break;}

else { System.out.print(" sorry we cant do nothing about " + enter );}

System.out.println( " do you want any thing else ? ");

System.out.print (" enter yes for yes and no for no ");

String chiocec =input.next();

String yes;

String no;

if(chiocec.equals("no")){

System.out.print( " okay goodbye " + name );

break;}

else if(chiocec.equals("yes")){continue;}
else {System.out.print(" sorry we said yes or no no " + chiocec );}

i++;

}while(i<100);

System.out.print("good bye " + name);

Das könnte Ihnen auch gefallen