Question

(NEED FULL CODE PLEASE)write a java program class to calculate and display the areas of 10 rectan...

(NEED FULL CODE PLEASE)write a java program class to calculate and display the areas of 10 rectangles using arrays.

* input validation sizes must be between 0-50 inches output to be displayed on the screen and send to an output file.

*the output must appear in the following format.

rectangle length width area

1    2.0    3.0    6.0

2

-

-

-

-

10

display the rectangle with largest area. rectangle1 area=

display the rectangle with smallest area. rectangle2 area=

0 0
Add a comment Improve this question Transcribed image text
Answer #1


/*
 *  Java Program
 *  Get Rectangle length and width from user
 *  Print and write Stats to file
 */

import java.util.*;
import java.io.FileWriter; 
import java.io.IOException;

class Main
{
  public static float getArea(float x, float y)
  {
    return x*y;
  }

  public static void main(String[] args) throws IOException
  {
    int MAX = 3;

    float rectLen[] = new float[MAX];
    float rectWidth[] = new float[MAX];
    float rectArea[] = new float[MAX];

    int largest = 0, smallest = 0;

    Scanner input = new Scanner(System.in);
    FileWriter file = new FileWriter("output.txt"); 
  

    for (int i = 0; i < MAX; i++)
    {
      System.out.print("Enter length and width for rectangle #" + (i+1) + ": ");
      rectLen[i] = input.nextInt();
      rectWidth[i] = input.nextInt();
      rectArea[i] = getArea(rectLen[i], rectWidth[i]);
    }

    System.out.println("Rectangle\tLength\tWidth\tArea");
    file.write("Rectangle\tLength\tWidth\tArea\n");

    for (int i = 0; i < MAX; i++)
    {
      System.out.println((i+1) + "\t" + rectLen[i] + "\t" + rectWidth[i] + "\t" + rectArea[i]);
      
      file.write((i+1) + "\t" + rectLen[i] + "\t" + rectWidth[i] + "\t" + rectArea[i] + "\n");

      if (rectArea[largest] < rectArea[i])
        largest = i;
      
      if (rectArea[smallest] > rectArea[i])
        smallest = i;

    }

    System.out.println("The rectangle with largest area is  rectangle #" + (largest + 1) + " with area = " + rectArea[largest]);

    System.out.println("The rectangle with smallest area is  rectangle #" + (smallest + 1) + " with area = " + rectArea[smallest]);

    file.close();

  }
}
/*  Program ends here */

@imtusharsharma/FelineLightgrayStruct shareは + new repl myrepis languages 요요 talk intusharshar.. Main.java saved https://Feli

Note: The program is tested and the output is attached. Please drop a comment for queries.

Add a comment
Know the answer?
Add Answer to:
(NEED FULL CODE PLEASE)write a java program class to calculate and display the areas of 10 rectan...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java... Write a class that has three overloaded static methods for calculating the areas of the...

    Java... Write a class that has three overloaded static methods for calculating the areas of the following geometric shapes: • circles -- area = π*radius^2 (format the answer to have two decimal places) • rectangles -- area = width * length • trapezoid -- area = (base1 + base2) * height/2 Because the three methods are to be overloaded, they should each have the same name, but different parameters (for example, the method to be used with circles should only...

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

  • This program needs to be in JAVA language. Also, I need to create my own LinkedList...

    This program needs to be in JAVA language. Also, I need to create my own LinkedList class, I can not use the Java LinkedList Library. Please read all aspects of the program, it needs to display 200 random numbers that are 5 digits long sorted from smallest to largest. I can not use Collection(s) or packages libraries. Should only need: import java.util.Random; import java.util.Scanner; Please provide output screenshots after the code. Thank you! You are going to create a Linked...

  • Making a rectangle class in java write a simple class that will represent a rectangle. Later...

    Making a rectangle class in java write a simple class that will represent a rectangle. Later on, we will see how to do this with graphics, but for now, we will just have to use our imaginations for the visual representations ofWthe rectangles. Instance Variables Recall that an object is constructed using a class as its blueprint. So, think about an rectangle on your monitor screen. To actually draw a rectangle on your monitor screen, we need a number of...

  • What to submit: your answers to exercises 2. Write a Java program to perform the following...

    What to submit: your answers to exercises 2. Write a Java program to perform the following tasks: The program should ask the user for the name of an input file and the name of an output file. It should then open the input file as a text file (if the input file does not exist it should throw an exception) and read the contents line by line. It should also open the output file as a text file and write...

  • This question is about java program. Please show the output and the detail code and comment.And...

    This question is about java program. Please show the output and the detail code and comment.And the output (the test mthod )must be all the true! Thank you! And the question is contain 7 parts: Question 1 Create a Shape class with the following UML specification: (All the UML "-" means private and "+" means public) +------------------------------------+ | Shape | +------------------------------------+ | - x: double | | - y: double | +------------------------------------+ | + Shape(double x, double y) | |...

  • in java PART ONE ================================================== Write a program that will read employee earnings data from an...

    in java PART ONE ================================================== Write a program that will read employee earnings data from an external file and then sort and display that data. Copy and paste the input file data below into an external file, which your program will then read. You will want to use parallel arrays for this program. Modify the select sort algorithm to receive both arrays as parameters as well as the size of the arrays. Use the algorithm to sort your earnings array....

  • Write a Java program called Flying.java that, firstly, prompts (asks) the user to enter an input...

    Write a Java program called Flying.java that, firstly, prompts (asks) the user to enter an input file name. This is the name of a text file that can contain any number of records. A record in this file is a single line of text in the following format: Num of passengers^range^name^manufacturer^model where: Num of passengers is the total number of people in the plane. This represents an integer number, but remember that it is still part of the String so...

  • QUESTIONS 13-18 PLEASE! Maximum Storage Area DUE DATE: This project is worth 10% of your Unit...

    QUESTIONS 13-18 PLEASE! Maximum Storage Area DUE DATE: This project is worth 10% of your Unit 2 grade. Please review the Project FAQ handout for format and process. Problem Situation A construction company wishes to build a rectangular enclosure to store machinery and equipment. The site selected borders on a river that will be used as one of the sides of the rectangle. Fencing will be needed to form the other three sides. The company foot high chain-link fencing. The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT