Write a program in java to implement the formula area=height*width




















Just for a subject purpose, we have shared another method here. If you have any doubts related to this query do comment here, we are glad to help you out. Below are the online compiler and execution tool check it out area of rectangle what is a rectangle? Lol :-p you knew it, but just a couple of lines The rectangle is a plane figure with four straight sides or just four right angles.

What is the formula for the area of a rectangle? The area of a rectangle formula is : Length X Breadth. Scanner ;. Output - area of rectangle. Enter the length :. Enter the breadth :. Area of Rectangle is : More Programs:. Static Method Static Method Program. Scanner ;. Enter the radius :. Area of circle : AreaOfCircle x ;. Using Inheritance. Area of Circle is : If I ran this program, I would seen an error immediately - wait a sec, my output looks like this:.

You can do a similar thing with your area-calculating code. Write a basic test which compares your code's output with a known value - that is, the value which you calculated by hand.

It is good to test values like 0 and 1 - but it is also good to test "non-obvious" numbers like " Ask your professor, you're already paying quite a bit for the class I'm sure so get help from him. Also, your goal is the complete the assignment the way the professor wants, plain and simple. The BEST person in the entire world suited to help you with that is the professor.

And to calculate the area or surface area, simply implement the algorithm in the getArea method. Here's an example to get your started, the constructors for different shapes will differ, and they are used to define the shapes.

One approach: When you are stuck, or, as many will argue, all the time , you should Start with the Test Code. Below I'm using skeletal JUnit3 for that, not sure what you are using in your class. Your imaginary thought process is in italics. I'll ask the teacher what he wants and hope I get extra credit!

Add that to your test code Finally, you should create a skeletal method to implement the algorithm, and work on it till the test succeeds.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Java area class Ask Question. Asked 12 years, 6 months ago. Active 2 years, 5 months ago. Viewed 6k times. PI, r is the cylinder's base, and h is the cylinder's height I also have to create an Area Test class as well and I don't know where to start. Improve this question.

DanM7 2, 3 3 gold badges 25 25 silver badges 45 45 bronze badges. Dale Williams Dale Williams. This is not rent-a-coder. What are you stuck on specifically? Sorry, I get even more confused. Well, I should've post my complete requirements for the code. Let me just re-edit my problem. The reason why I don't want to edit my complete problem is I am not even half way done with my main code, because I got confused on how to set 4 objects of box into array, can go through each of them and find the length, width, height, area, and volume.

You haven't declared those doubles in your constructor. Luis Lavieri Luis Lavieri 3, 6 6 gold badges 35 35 silver badges 64 64 bronze badges. If you want to be technical about it, your Box object should not be allowed to mutate once created a real-world box doesn't change dimensions once created. Therefore, your objects should be immutable no setter methods and parameters should be final — hfontanez.

Chris Chris 5 5 silver badges 19 19 bronze badges. I apologize for that. The task you are describing is not quite clear to me, because IMHO it does not make sense to declare an array of boxes, with 4 boxes in it and then afterwards go through the boxes and set the attributes.

Sounds like the typical school question with no practical relevance ;- Anyway - I'll try and edit my answer. Another thing as a comment: People here are often very unhappy with beginners questions, and you might not get answers. Try a forum like coderanch. Storing the boxes If this is a single-class project, maybe you want to make this collection most likely a java. Sign up or log in Sign up using Google. Sign up using Facebook.

Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked 2. Related



0コメント

  • 1000 / 1000