Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA Please help me do these questions. 1 st Task– Write a program where you dec

ID: 3667057 • Letter: J

Question

JAVA

Please help me do these questions.

1st Task–

Write a program where you declare 4 different variables that add up 100, with the program auto-calculating the 5th variable / integer which is 100..

Print output with:

Var1 is “integer”, Var 2 is “integer”, Var 3 is “integer”, Var 4 is “integer”   // all numbers on Same Line

(Blank Line)

var1 + var2 + var3 + var4 = var5 (equal to 100)

2st Task–

in Programming A Comprehensive Introduction

#13. The moon’s gravity is about 17 percent that of the earth’s. (Meaning you weigh less on the moon). Write a program that computes your affective weight on the moon.

Once you have completed your Program attach a picture of your program to this assignment and submit using your flash drive during lab-time.

Explanation / Answer

TASK 1:
import java.util.Scanner;

/**
* @author Srinivas Palli
*
*/
public class AddUpToHunderedTask1 {

   /**
   * @param args
   */
   public static void main(String[] args) {
       Scanner scanner = null;

       try {
           scanner = new Scanner(System.in);
           int var1, var2, var3, var4, var5;

           System.out.print("Enter 1st Integer:");
           var1 = scanner.nextInt();

           System.out.print("Enter 2st Integer:");
           var2 = scanner.nextInt();

           System.out.print("Enter 3st Integer:");
           var3 = scanner.nextInt();

           System.out.print("Enter 4st Integer:");
           var4 = scanner.nextInt();

           var5 = 100 - (var1 + var2 + var3 + var4);
           System.out.println("Var1 is " + var1 + ", Var 2 is " + var2
                   + ", Var 3 is " + var3 + ", Var 4 is " + var4
                   + " , Var 5 is " + var5 + " ");

       } catch (Exception e) {
           // TODO: handle exception
       }

   }
}

OUTPUT:
Enter 1st Integer:12
Enter 2st Integer:45
Enter 3st Integer:18
Enter 4st Integer:4
Var1 is 12, Var 2 is 45, Var 3 is 18, Var 4 is 4 , Var 5 is 21

Task2:
import java.util.Scanner;

/**
* @author Srinivas Palli
*
*/
public class WeightOnMoon {

   /**
   * @param args
   */
   public static void main(String[] args) {

       try {
           Scanner scanner = new Scanner(System.in);
           System.out.print("Enter the weight on the earth:");
           double weightOnEarth = scanner.nextDouble();
           double weightOnMoon = weightOnEarth * (1.0d / 6.0d);
           System.out.println("Affective weight on the Moon:" + weightOnMoon);
       } catch (Exception e) {
           // TODO: handle exception
       }
   }
}
OUTPUT:
Enter the weight on the earth:14
Affective weight on the Moon:2.333333333333333