A Simple program
Hi I have written the following code:
class FirstRectangle{
public int rectArea(int l,int b){
int farea = l*b;
System.out.println("Required Area::"+farea);
return farea;
}//method
}//class
class SecondRectangle{
public int area(int l, int b){
int sarea = l*b;
System.out.println("Required Area::"+sarea);
return sarea;
}//method
}//class
public class MyShape{
public void combinedArea(FirstRectangle r,SecondRectangle sr){
r.rectArea(10,5);
sr.area(15,10);
}//method
public static void main(String []s){
FirstRectangle r = new FirstRectangle();
SecondRectangle sr = new SecondRectangle();
MyShape m = new MyShape();
m.combinedArea(r,sr);
}//main
}//class
I want to add the area both rectangles and display them, but not getting how to do that. Please help me.
View Answers
December 15, 2010 at 11:43 AM
Hi Friend,
Here is your required code:
class FirstRectangle{
public int rectArea(int l,int b){
int farea = l*b;
System.out.println("Required Area::"+farea);
return farea;
}
}
class SecondRectangle{
public int area(int l, int b){
int sarea = l*b;
System.out.println("Required Area::"+sarea);
return sarea;
}
}
public class MyShape{
public void combinedArea(FirstRectangle r,SecondRectangle sr){
int area1=r.rectArea(10,5);
int area2=sr.area(15,10);
int sum=area1+area2;
System.out.println("Combined Area is: "+sum);
}
public static void main(String []s){
FirstRectangle r = new FirstRectangle();
SecondRectangle sr = new SecondRectangle();
MyShape m = new MyShape();
m.combinedArea(r,sr);
}
}
Thanks
December 15, 2010 at 12:05 PM
Thanks for the solution. Now its working.
One more thing I need to ask:
Is there any provision by which I can directly use farea and sarea for calculating the sum. I mean say the respective calculated values are stored in farea and sarea. Can't I use them directly?
Related Tutorials/Questions & Answers:
A Simple programA
Simple program Hi I have written the following code:
class FirstRectangle{
public int rectArea(int l,int b){
int farea = l*b;
System.out.println("Required Area::"+farea);
return farea
Advertisements
Simple JSP program exampleSimple JSP
program example Hi,
How to make
simple jsp
program... with the
simple JSP example
program.
Give me
simple jsp
program example.
Thanks
HI,
The very
simple JSP
program is to display the current date on the JSP
simple program questionsimple program question how do i get a java
program to take an input from the user and have it terminate by a period and not by pressing enter
Simple JSP programSimple JSP program create a
simple jsp page in which number is to be entered by user in jsp page and submit button clicked.If number entered is greater then 100,then message box "no is greater" elseif less "no is lesser
Help me to write this simple java frame program Help me to write this
simple java frame
program I want to write a Java
program for....
To create a frame with 4 text fields;name,street,city and pin;with suitable labels.
Also add a button "OK". After enter values
Simple Program Very Urgent.. - JSP-ServletSimple Program Very Urgent.. Respected Sir/Madam,
I am R.Ragavendran.. Thanks for your superb reply. I find a
simple problem which i have tried my level best to solve.In the output, the text box is receiving some other value
Simple Java class program - Java BeginnersSimple Java class program Hi sir,
Please help me Write a
simple class that iterates through all the arguments passed in on the command line and prints them out to the screen.
If no arguments are specified print a message
Simple Java class program - Java BeginnersSimple Java class program Hello,
Please help me, Write a
simple class that iterates through all the arguments passed in on the command line and prints them out to the screen.
If no arguments are specified print a message
Class Average Program
Class Average
Program
This is a
simple program of Java class. In this
tutorial we will learn how to use java
program for displaying average value. The
java instances
Simple java program
Simple java
program
Hi this is the thing we got to do and i am totally confused on how to write this
program it would be a great help i could be helped... that
program. plz do help me out here.
Part I
Write a
program Writing Simple Java Script Program
Writing
Simple Java Script
Program
... of JavaScript and
create your first JavaScript
program.
Creating your first JavaScript ProgramADS_TO_REPLACE_1
In the last lesson you learned how to create
simple Simple program to combine all html,ajax,java,servlets,jsp,json - Java BeginnersSimple program to combine all html,ajax,java,servlets,jsp,json Hi... a
program which is a combination of all those technology. For that, i planned to design a
simple html page with a input field and submit button. I tried to do
programprogram An old-style movie theater has a
simple profit
program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus $.50 per attendee. Develop the
program calculateTotalProfit that consumes
programprogram . Develop a
program that accepts an initial amount of money (called the principal), a
simple annual interest rate, and a number of months will compute the balance at the end of that time. Assume that no additional
programprogram any
program of hotel or school management
programprogram
program of jdbc using ms access for creating table
programprogram write a javascript
program to create a application form with validation
programprogram write a html
program in show table and this word
in box
programprogram write a
program different between to dates in terms of days in java
programprogram WAP a java
program to form 1/2+3/4+5/6+7/8 series
programprogram Write a
program to find the difference between sum of the squares and the square of the sums of n numbers
programprogram write a
program reversee a string.
input-hi this is roseindia
output-roseindia is this hi
programprogram develop a servlet to insert the data in the database from our
program in the table stored in the database
programprogram write a java
program to input a no. and print wheather the no. is a special no or not. (special no. are those no whose factorial of the sum of digit of the no is same as the original
programprogram Develop the
program calculateCylinderArea, which accepts radius of the cylinder's base disk and its height and computes surface area of the cylinder
programprogram explanation of
program on extending thread class
Hi Friend,
Please go through the following link:ADS_TO_REPLACE_1
Java Threads
Thanks
programprogram Develop a
program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time, and the Pythagorean
programprogram how to improve programming skills plss tell some tips..i am understanding concepts but unable to write
program so,pls give some guideness plsss
ProgramProgram a
program to prove that default constructor of super class is available to subclass by default. Define a parameterize constructor for super class to store name = â??Tommyâ?? age=â??23â?? and call this constructor
ProgramProgram a
program to create two classes Commercial and Domestic. Override the method calculatebill() of Commercial class(Rs.8 per unit) into Domestic class(Rs 6 per unit) to compute electricity bill for both classes
programprogram no i want a
program that shows how merge sort algorithm works in graphical representations like numbers are taken in circles and computation... in rectangles or circles wat ever it may be. the theme of
program is to show algorithm
programprogram Write a JSP
Program, which displays a web page containing the name of the Courses, Courses being offered currently, number of students enrolled in each course, new courses to be offered, eligibility criteria for taking
programprogram i want a progra in java to print a sentence in alphabetic order, taking the input from the user.the
program should writen without using the array
for example : if input= this is a cat
then output sould = a cat
programprogram Utopias tax accountants always use programs that compute income taxes even though the tax rate is a solid, never-changing 15%. Define the
program calculateTax which determines the tax on the gross pay. Define
programprogram Write a JSP
Program, which displays a web page containing two web links one for your profiling and other for the schedule of theory of practical classes of your Batch. When one click on link for getting your profile
programprogram Write a
program to print details of a week for a particular day using array of objects Integer and String.
OUTPUT:
First Day of Week is Monday
Second Day of Week is Tuesday
Third Day of Week is Wednesday
Forth Day
jQuery to Simple Image ScrollerjQuery to
Simple Image
Scroller
In this first jQuery tutorial we will develop a
program that simple
image scrollerADS_TO_REPLACE_1
Steps to develop the
program jQuery To Simple tabs
jQuery To
Simple tabs
In this JQuery tutorial we will develop a
program to make
simple tabs ADS_TO_REPLACE_1
Steps to develop the
simple tabs .
Step 1:
ADS
Create First Program Create First
Program
In this section, you will learn to write a
simple
Java
program. For developing a java
program you just need a
simple text editor
Three Dimensional Array program
Three Dimensional Array
program
This is a very
simple Java
program. In this
program we...
name "ThreeDMatrix" . We are going to create 3 by 4 by 5
program. We
Two Dimensional Array Program;
This is very
simple program of Java. In this lesson we
will learn how to display arrange form of two dimensional array
program... a integer for array declaration Two dimensional array
program. We are going