Question

Write a java program that specifies three parallel one dimensional arrays name length, width, and area....

Write a java program that specifies three parallel one dimensional arrays name length, width, and area. Each array should be capable of holding a number elements provided by user input. Using a for loop input values for length and width arrays. The entries in the area arrays should be the corresponding values in the length and width arrays (thus, area[i] =   length [i]* width [i]) after data has been entered display the following output: (in Java)

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

Here is the answer for your question in Java Programming Language.

NOTE : Unfortunately your sample output was not loaded if you provided. I have given possible sample outputs in the code. Please check them and uncomment the respected code to use the code. Thank you.

Comment below if you need any further help.

CODE :

import java.text.DecimalFormat;
import java.util.Scanner;

public class calculateAreas {

public static void main(String[] args){

//Required variables and objects
int n;
DecimalFormat f = new DecimalFormat("#.##");
Scanner s = new Scanner(System.in);
//Reading number of elements in array
System.out.print("Enter number of elements you want to enter in the arrays : ");
n = s.nextInt();

//Creating three parallel arrays to be able to hold numbre of elements entered by user
double[] length = new double[n];
double[] width = new double[n];
double[] area = new double[n];

//Reading lengths and widths and calculating areas
System.out.println("------------------------------------------------");
for(int i=0;i<n;i++){
System.out.print("\nEnter length #" + (i+1) + " : ");
length[i] = s.nextDouble();
System.out.print("Enter width #" + (i+1) + " : ");
width[i] = s.nextDouble();
//Calculating area
area[i] = length[i]*width[i];
}
System.out.println("------------------------------------------------");
//Displaying output
//Sample Output - 1
System.out.println("\n----------------------------------------------------------");
System.out.println("Length\tWidth\tArea(sq.m)");
System.out.println("----------------------------------------------------------");
for(int i=0;i<n;i++){
System.out.println(String.format("%-20.2f%-20.2f%.2f",length[i],width[i],area[i]));
}

//Sample Output - 2
/*
System.out.println("----------------------------------------------------------");
for(int i=0;i<n;i++){
System.out.println("For length = " + length[i] + " m and width = " + width[i] + " m the area is " +f.format(area[i]) + " sq.m");
}
System.out.println("----------------------------------------------------------");
*/

//Sample Output - 3
/*
System.out.println("===========================================================");
for(int i=0;i<n;i++){
System.out.println("Length = " + length[i] + " m\nWidth = " + width[i] + " m\nArea = " + f.format(area[i]) + " sq.m");
System.out.println("------------------------------");
}
System.out.println("===========================================================");
*/
}
}

SCREENSHOTS :

Please see the screenshots of the code below for indentations of the code.

1 „ import java.text.DecimalFormat; import java.util.Scanner; 2 3 4 5 public class calculateAreas { 6 public static void main31 32 33 34 35 36 37 38 39 System.out.println(. -); //Displaying output // Sample Output - 1 System.out.println(\n-- -);

OUTPUT :

Sample output - 1 :

run: Enter number of elements you want to enter in the arrays : 5 Enter length #1 : 13.5 Enter width #1: 1.3 Enter length #2

Sample output- 2 :

run Enter number of elements you want to enter in the arrays : 5 Enter length #1 : 15.6 Enter width #1 : 3.4 Enter length #2

Sample output - 3 :

run: Enter number of elements you want to enter in the arrays : 5 Enter length #1 : 45.6 Enter width #1:5.6 Enter length #2 :Length = 15.6 m Width = 5.5 m Area = 85.8 sq.m Length = 19.8 m Width = 4.5 m Area = 89.1 sq.m Length = 78.6 m Width = 34.6 m

Any doubts regarding this can be explained with pleasure :)

Add a comment
Know the answer?
Add Answer to:
Write a java program that specifies three parallel one dimensional arrays name length, width, and area....
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
  • Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values,...

    Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values, of same size         b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....

  • IN JAVA... Write a program that would create a one-dimensional array of length 7, with user-specified...

    IN JAVA... Write a program that would create a one-dimensional array of length 7, with user-specified values and display the array values. Then search the array for the smallest value and display both the value and its position in the array.

  • Write a program that calculates voltage from current and resistance values. Create three one-dimensional arrays named...

    Write a program that calculates voltage from current and resistance values. Create three one-dimensional arrays named current, resistance and voltage, each capable of holding 10 double-precision values. The values stored in current and resistance are as follows: current = 10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, 3.98 resistance = 4.0, 8.5, 6.0, 7.35, 9.0, 15.3, 3.0, 5.4, 2.9, 4.8 Have your program pass these three arrays to a function called calcVolts() which calculates the elements in the voltage...

  • Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs...

    Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs six numbers [Keep the numbers in an array]. The numbers must be between 20 and 200, inclusive. If the number is not between 20 and 200, ask for another input. When a number is entered, display the number only if it is not a duplicate of a number already entered. If it is a duplicate of a number already entered, display a message that...

  • I keep getting redefinition errors and undeclared identifiers 3. (20 points. Lastname_Lab6 p3.cpp) Write a program...

    I keep getting redefinition errors and undeclared identifiers 3. (20 points. Lastname_Lab6 p3.cpp) Write a program that declares three one dimensional arrays named price, quantity, and amount. Each array should be declared in main ) and should be capable of holding ten double-precision numbers. The numbers that should be stored in price are 10.64, 14.89,15.21,74.21,23.8,61.26,92.37, 12.73, 2.99, 58.98. The numbers should be stored in quantity are 4, 8,17,2,94,61,20,78,55,41. You program should pass these three arrays to a function named extend...

  • public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which...

    public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which does the following: In the main method: Use a for loop which repeats three times. Within the loop, a. prompt the user to enter the base of the triangular prism and store the value in a double array called base b. prompt the user to enter the corresponding height and store the value in a double array called height c. prompt the user to...

  • java Create a program that utilized a multi-dimensional array for the user to input the name...

    java Create a program that utilized a multi-dimensional array for the user to input the name of a team and their number of wins. The user should be able to input up to 10 teams and the wins for each team.

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • The goal of this assignment is to practice one dimensional arrays. Objective: The goal of this...

    The goal of this assignment is to practice one dimensional arrays. Objective: The goal of this assignment is to practice one-dimensional arrays. Background: A local FedEx ship center needs support to compute volume of the packages that are delivered on each day Assignment: The shipping center manages deliveries of each day in a single text file. Each text file contains exactly three lines. Each line contains n double numbers representing a dimension of n boxes. The first line represents the...

  • Write a program to display the area of a rectangle after accepting its length and width...

    Write a program to display the area of a rectangle after accepting its length and width from the user by means of the following functions: getLength – ask user to enter the length and return it as double getWidth – ask user to enter the width and return it as double getArea – pass width and length, compute area and return area displayArea – pass area and display it in this function. Expected Output: (i) Enter the length: 29 Enter...

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