Home Answers Viewqa Java-Beginners A Simple program

 
 


Nitish Kumar
A Simple program
2 Answer(s)      2 years and 5 months ago
Posted in : Java Beginners

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 Pages:
simple program
simple program  how to print * like triangle
A Simple program
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
simple calculator program in javascript
simple calculator program in javascript  strong textsimple calculator in javascript
simple program question
simple 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 webdesign program with coding
simple webdesign program with coding  how to design a webpage using html   Please go through the following link: HTML Tutorials
Simple JSP program
Simple 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
simple pgm
simple pgm  a java program which uses super class
simple eg
simple eg   <?php</li> $string = ?Hello Users?; print (?Welcome to Roseindia, I want to greet $string?); print (??); $string = ?Bye Bye!?; print (?OK meet you soon, $string?); ?> in this program we get a error at line
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
program
program   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
Simple Java class program - Java Beginners
Simple 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 Beginners
Simple 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
program
program  . 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
Simple Program Very Urgent.. - JSP-Servlet
Simple 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 FTP upload in Java
Simple FTP upload in Java  How to write a program for Simple FTP upload in Java? Any code example of Simple FTP upload in Java will be very helpful for me. Thanks
simple team leader
simple team leader  Could you please help me to write a program for a simple team leader?   Please clarify your problem. Which type of program you want to create in java? Please specify
to find simple interst
to find simple interst  create a class of object insert with a constructor. write a program to find out simple interest   import java.util.... si=p*rate*t; System.out.println("Simple Interest: "+si); } public
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
Simple ATM Java Code...
Simple ATM Java Code...  You are required to write a Graphical User Interface that simulates an ATM by building on the program you wrote..., or provide the current balance. Your program must perform the following: Read
jQuery To Simple tabs
jQuery To Simple tabs       In this JQuery tutorial we will develop a program  to make simple tabs  Steps to develop the simple tabs . Step 1:        
jQuery to Simple Image Scroller
jQuery to Simple Image Scroller       In this first jQuery tutorial we will develop a  program that simple  image scroller Steps to develop the program Step 1
A simple question - Java Beginners
A simple question   Design a program to calculate either the square of a number or the square root of a number and display the results. output should be like:- Enter a float value: 6.2 Do you want the (s)quare or square (r
Very simple `Hello world' java program that prints HelloWorld
Hello World Java Simple Java Program for beginners... to develop robust applications. Writing a simple Hello World program is stepwise... HelloWorld.java - the source code for the "Hello, world!" program
Example - Simple Calculator
) - A simple main program. User interface (CalcGUI.java... Java: Example - Simple Calculator Here is the source for the simple... place. Altho this simple example doesn't show the full power of separating
Writing Simple Java Script Program
Writing Simple Java Script Program   ... of JavaScript and create your first JavaScript program. Creating your first JavaScript Program In the last lesson you learned how to create simple java script
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
session realtime usage program simple jsp program or servlet ,which understands me importance of session
session realtime usage program simple jsp program or servlet ,which understands... like client state storage scope.,but jsp or servlet realtime simple session related program whether it may be loginpage or anything must simple understanding
Simple Form in Java
Simple Form in Java       This is a simple program of java awt package which constructs a look like... awt package. Program Description: Here, all the components like text boxes
Simple Linked Lists
" The following program is an example of a very simple implementation of a singly-linked... Java Notes: Simple Linked Lists This shows three programs. A simple... as simple as the singly-linked list, but makes some operations easier
Simple Java Calculator - Java Beginners
Simple Java Calculator  Write a Java program to create simple Calculator for 4 basic Math operations, Addition, Subtraction, Multiplication and Division. The calculator should simulate the look of handheld calculator containing
PHP Registering simple statistics
that they visited ! This program follows a simple algorithm as follows: 1. Grab... PHP Registering simple statistics Have you ever wanted to know who visited... ! In this tutorial I will teach you how to make a simple PHP Script that writes
Java: Example - Simple Calculator
(Calc.java) - A simple main program. User interface (CalcGUI.java... Java: Example - Simple Calculator Here is the source for the simple... place. Altho this simple example doesn't show the full power of separating
code for a simple java program which performs basic arithmetic operation addition,subtraction,multiplication,division........
code for a simple java program which performs basic arithmetic operation addition,subtraction,multiplication,division........  code for a simple java program which performs basic arithmetic operation addition,subtraction
Java simple question - Java Beginners
Java simple question  I have to design a program for a trucking company that has 7 trucks in its fleet. Each truck is identified by a number, 1-7.... Truck 7 Max = 30K weight = 20K. (8 possible dialog boxes: program instructions
Simple problem to solve - JSP-Servlet
Simple problem to solve  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your kind and timely help for the program I have asked earlier. Its working in a fantastic way. My heartiest solute to Roseindia team
Simple problem to solve - JSP-Servlet
Simple problem to solve  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your kind and timely help for the program I have asked earlier. Its working in a fantastic way. My heartiest solute to Roseindia team
Simple Linked List Exercise 1
Java Notes: Simple Linked List Exercise 1 Name: ___________________________________________ Fill in the blanks to for this program that reads strings and puts them in a doubly linked list. 1 2 3 4 5 6 7 8
Simple program to combine all html,ajax,java,servlets,jsp,json - Java Beginners
Simple 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
Ajax program
Ajax program  any simple program with execution steps using netbeans 6.9
JMS Program
JMS Program  Is it possible for anyone to post simple JMS Program and explanation in understandable way
Simple Date Format Exception
Simple Date Format Exception       Simple Date Format Exception inherits from a package name... and normalization of date. Simple Date-format provides you to work on choosing any
Simple Calculator Application In Java Script
the basics of JavaScript and create your first JavaScript program. What is simple Calculator The objective of this project is  learn how to write a simple... Simple Calculator Application In Java Script  
A simple example of log4j
A simple example of log4j       This Example shows you how to create a log in a program. Description of the code: Logger.getLogger
How to run a simple jsp page in tomcat???
How to run a simple jsp page in tomcat???  i am trying to run a simple jsp page in tomcat,i am having web.xml also in WEB-INF folder...;yes...i did. i.e SET CLASSPATH=.;C:\Program Files\Apache Software Foundation
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 like
write simple java code - Java Beginners
write simple java code  Write a program that creates a simple calculator .The user enters two numbers in the text fields, Number 1 and Number 2... integers will be displayed in the Result text field. The program handles two kinds
Simple Counter In Servlet
() to write a logic of the program. Our program logic is simple. We have to just... Simple Counter in Servlet     ... a program on counter which will keep track how many times the servlet has been
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
Java Program
Java Program  A Simple program of JSP to Display message, with steps to execute that program   Hi Friend, Follow these steps: 1)Go.../hello.jsp and press enter. 9)You jsp program will then display the output

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.