# Please find me a solution that

ali
Please find me a solution that
Posted in : Java Interview Questions

Write a java program that calculates the area of rectangular, square,

triangular, and circle.

Your program must have the following:

1. Two classes named "Area" and "AreaTest".

2. Class "Area" has the following:

a. Void Square Method with one parameter which is length of

side.

b. Void Rectangle Method has two parameters which are

width and height.

c. Void Triangle Method has two parameters which are base

and vertical height.

d. Void Circle Method has one parameter which is radius.

You must use Math.PI and Math.pow() function for your

calculation.

e. One Void Display Method to print out the calculation result

for all methods (Square, Rectangle, Triangle, and Circle). For

example, if I want to print the area of rectangle, you have to

pass the result as a parameter to Display Method to print it

out. There is one System.out.printf() in this method and

must be as following format:

System.out.printf("The Area of %s is %s" ,str,result);

str = any of these words: Square, Rectangle, Triangle ,or

Circle.

Result = the result of the method calculation.

f. Do not use Instance Variable for your program.

1. Class "AreaTest" has the following:

a. Switch statement that maintains accessing each of the

method in (a),(b), (c), and (d) stated above in class "Area"

b. 'For statement loop' to keep the user running your program

until he enters number '5' to exit the program.

May 16, 2012 at 4:14 PM

The given code calculates the area of square, rectangle, triangle and circle. It allow the user to enter their choice. It then takes the user request and display the result accordingly.

```import java.util.*;

class Area
{
public static double square(double side){
double area=side*side;
return area;
}
public static double rectangle(double width,double height){
double area=width*height;
return area;
}
public static double triangle(double base,double height){
double area=(base*height)/2;
return area;
}
return area;
}
public static void display(String str,double result){
System.out.println("The Area of "+str+" is: "+result);
}
}

class AreaTest{
public static void main(String[] args)
{
boolean exit=false;
String str=" ";
Scanner input=new Scanner(System.in);
do{
System.out.println("1 Square");
System.out.println("2 Rectangle");
System.out.println("3 Triangle");
System.out.println("4 Circle");
System.out.println("5 Exit");

int choice=input.nextInt();
switch(choice){
case 1:
System.out.print("Enter side: ");
double s=input.nextDouble();
str="Square";
Area.display(str,Area.square(s));
break;

case 2:
System.out.print("Enter width: ");
double w=input.nextDouble();
System.out.print("Enter height: ");
double h=input.nextDouble();
str="Rectangle";
Area.display(str,Area.rectangle(w,h));
break;

case 3:
System.out.print("Enter base: ");
double b=input.nextDouble();
System.out.print("Enter height: ");
double ht=input.nextDouble();
str="Triangle";
Area.display(str,Area.triangle(b,ht));
break;

case 4:
double r=input.nextDouble();
str="Circle";
Area.display(str,Area.circle(r));
break;

case 5:
exit=true;
System.exit(0);
}
}
while(!exit);

}
}
```

Please find me a solution that
Please find me a solution that   Write a java program that calculates the area of rectangular, square, triangular, and circle. Your program must have the following: Two classes named "Area" and "AreaTest". Class "Area
error please send me the solution
error please send me the solution  HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception
error please send me the solution
error please send me the solution  HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception
Please tell me where I can find tutorials on spring hibernate?
Please tell me where I can find tutorials on spring hibernate?  Hello, Please tell me where I can find tutorials on spring hibernate? Thanks..   Dear Friend, You can find some good tutorials on Spring Hibernate here
Insertion sort program find calendar to array value 1000,5000,10000  program find calendar for insertion sort in jfram to array 1000
Please tel me .In my System Oracle9i and J2sdk1.6 are Installed.Why this problem occures and what is the solution?
Please tel me .In my System Oracle9i and J2sdk1.6 are Installed.Why this problem occures and what is the solution?  Exception in thread "main" java.lang.UnsupportedClassVersionError: select (Unsupporte d major.minor version 50.0
please give me solution how to display next page after 20 records ? - JSP-Servlet
please give me solution how to display next page after 20 records ?  Java Servlet Paging control example  here i have attached one example code. function validate() { for(j=0;j<30;j
Can find a solution or code for this - XML
Can find a solution or code for this   Develop a java based tool which can be used to build a GUI structure based on the configurations given in the tool. Input XML Folders/Files E.g:Folder for Main Panel Files for required
(); ^ 1 error tell me the resolution please....   import...please tell me  import java.lang.Thread; class Current{ public static... error as Current.java:7: cannot find symbol symbol : method CurrentThread
)); ^ 1 error please tell me the resolution of this   Hi...please tell me  import java.io.*; class SString{ public static void...: cannot find symbol symbol : class Bufferedreader location: class SString
(10.6,20.0); ^ 1 error, please tell me the resolution for this...   ...please tell me  class Sample{ private double num1,num2; void sample...\oops>Javac Methods.java Methods.java:14: cannot find symbol symbol
please tell me  class Producer extends Thread { StringBuffer sb... got error as Inner class connot have static declarations pls tell me the solution for this   class Producer extends Thread { StringBuffer sb
please tell me  i have created one table,when i close and again login, table name will be there, but its content not displayed, showing as no rows selected, please tell me the reason
help me please   Hello I want helping for this question , Please Write a program that reads some friendsÃ¢â?¬â?¢ names, stores them in an array, and then prints out on the screen all friends who start by a particular letter
"int a=08 or 09" its giving compile time error why   "int a=08 or 09" its giving compile time error why ? can any one give me the answer of this please
please help me.  I have a jsp page under that i add a list box under i get the countries through my database. so how can i do
please guide me  Hi I am Pradeep singh ,done SCJP 5.0 and SCWCD 5.0 .Now i want to learn further .So please tell me whether should i learn EJB 3.0... advice me .At present i am jobless
please help me to this problem..  i wrote a program like keyboard... inside the JTextField) but i want to make this program to let me write where i clicked (i.e allows me to write any thing at the field where i clicked
please help me...  write an application that print number in the following order using a FOR-Loop 1 2 3 4 5 2 4 6 8 10 3 6 9 1215 4 8 121620 5 10152025
please help me.  I have three table in mysql,and i hava create a excel sheet and add this sheet.but my question is in every sheet i can display one one table result.how can i do
Please help me.  Hi i am trinath in below there is a url.In that url there is a code of edit a jsp page.I understand that code but only one thing i not get it i.e; What is the work of "id".and what is the data type of id? http
please help me in these prog   create 2 jdbc programs including awt create 2 jdbc programs including swing create 2 jdbc programs including command line argument create 2 jdbc programs including io class 4 jdbc prog using
before. This name list should get from the database. Please help me. By the way, I'm...please help me  Dear sir, I have a problem. How to write JSP coding, if a user select a value from drop down list for example department, the another
, but its compiled and run successfully, please tell me the reason...please tell me  class Person{ int age; String name; void Person1(String g,int a){ name=g; age=a; } Person(String s,int i){ name=s; age=i; } void
: '}' expected ^ 2 errors, i got this error....... please tell me the resolution...please tell me  class Person{ string name; int age; void talk(){ System.out.println("my name is"+name); System.out.println
Please give me coding for this..
Please give me coding for this..  Write an application that inputs one number consisting of five digits from the user.separates the number ibto its individual digits and prints the digits separated from one another by three
Tutorials