The area of a rectangle is the rectangle\'s length times its width. Write a prog
ID: 3694218 • Letter: T
Question
The area of a rectangle is the rectangle's length times its width. Write a program that asks for the length and width of two rectangles. The program should tell the user which rectangle has the greater area, or if the areas are the same. Scientists measure an object's mass in kilograms and its weight in newtons. If you know an object's mass, you can calculate its weight in newtons with the following formula: weight 0 mass 9.8 Write a program that asks the user to enter an object's mass, and then calculates and displays its weight. If the object weighs more than 1000 newtons, display a message indicating that it is too heavy. If the object weighs less than 10 newtons, display a message indicating that the object is too light.Explanation / Answer
1)RectanglesAreaCompare.java
package org.students;
import java.util.Scanner;
public class RectanglesAreaCompare {
public static void main(String[] args) {
//decalaring varibles.
double area1,area2,length1,width1,length2,width2;
//Scanner object is used to get the input from the user.
Scanner sc=new Scanner(System.in);
System.out.print("Enter Length of the First Rectangle:");
length1=sc.nextInt();
System.out.print("Enter Width of the First Rectangle:");
width1=sc.nextInt();
System.out.print("Enter Length of the Second Rectangle:");
length2=sc.nextInt();
System.out.print("Enter Width of the Second Rectangle:");
width2=sc.nextInt();
//Calculating area
area1=length1*width1;
area2=length2*width2;
if(area1>area2)
{System.out.println(":: The Area of First Rectangle is greater than Second Rectangle ::");}
else if(area1<area2)
{System.out.println(":: The Area of First Rectangle is lesser than Second Rectangle ::");}
else
{System.out.println(":: The Area of First Rectangle is equal to Second Rectangle ::");}
}
}
__________________________________________________________________________________________
output:
Enter Length of the First Rectangle:5
Enter Width of the First Rectangle:6
Enter Length of the Second Rectangle:5
Enter Width of the Second Rectangle:6
The Area of First Rectangle is equal to Second Rectangle
______________________________________________________________________________________
output2
Enter Length of the First Rectangle:4
Enter Width of the First Rectangle:5
Enter Length of the Second Rectangle:6
Enter Width of the Second Rectangle:7
The Area of First Rectangle is lesser than Second Rectangle
_________________________________________________________________________________________
output:
Enter Length of the First Rectangle:4
Enter Width of the First Rectangle:5
Enter Length of the Second Rectangle:2
Enter Width of the Second Rectangle:3
The Area of First Rectangle is greater than Second Rectangle
___________________________________________________________________________________________
2)MassWeight.java
package org.students;
import java.text.DecimalFormat;
import java.util.Scanner;
public class MassWeight {
public static void main(String[] args) {
//To format the output
DecimalFormat df=new DecimalFormat("#.##");
//Scanner object is used to get the input from the user.
Scanner sc=new Scanner(System.in);
System.out.print("Enter the Object Mass(in Kgs):");
double mass=sc.nextDouble();
//Calculating Weight
double weight=mass * 9.8;
//Displaying Weight.
System.out.println("The Weight is:"+df.format(weight)+" N");
if(weight>1000)
{
System.out.println(":: Its Too Heavy ::");
}
else
{
System.out.println(":: Its Too Light ::");
}
}
}
___________________________________________________________________________________________
output:
Enter the Object Mass(in Kgs):200
The Weight is:1960 N
:: Its Too Heavy ::
_________________________________________________________________________________
output2:
Enter the Object Mass(in Kgs):4
The Weight is:39.2 N
:: Its Too Light ::
______________________________________________________________________________________
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.