Skip to content

Commit d92c8cb

Browse files
Mass and Weight
1 parent a32d38d commit d92c8cb

File tree

3 files changed

+87
-18
lines changed

3 files changed

+87
-18
lines changed

Programming-Challenges/Decision-Structures/.idea/workspace.xml

Lines changed: 46 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Scientists measure an object’s mass in kilograms and its weight in Newtons.
3+
If you know the amount of mass that an object has, you can calculate its weight, in Newtons, with the following formula:
4+
5+
Weight = Mass x 9.8
6+
7+
Write a program that asks the user to enter an object’s mass, and then calculate its weight.
8+
If the object weighs more than 1,000 Newtons, display a message indicating that it is too heavy.
9+
If the object weighs less than 10 Newtons, display a message indicating that the object is too light.
10+
*/
11+
12+
package com.challenges;
13+
14+
import java.util.Scanner;
15+
16+
public class MassAndWeight {
17+
public static void main(String [] args) {
18+
19+
// Declare Variables
20+
double weight;
21+
double mass;
22+
final double GRAVITY_CONSTANT = 9.8;
23+
24+
Scanner scanner = new Scanner(System.in);
25+
26+
System.out.println("Please enter mass of an object: ");
27+
mass = scanner.nextDouble();
28+
29+
weight = mass * GRAVITY_CONSTANT;
30+
31+
if(weight > 1000) {
32+
System.out.printf("The weight of the object is %.1f Newtons. The object is too heavy!", weight);
33+
}
34+
else if(weight < 10) {
35+
System.out.printf("The weight of the object is %.1f Newtons. The object is too light!", weight);
36+
}
37+
else {
38+
System.out.printf("The weight of the object is %.1f", weight);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)