Question
Topics: Entering, compiling, and running a Java program. Using arithmetic expression & casting Using Scanner class for input Important Note: All submitted assignments must begin
Topics: Entering, compiling, and running a Java program. Using arithmetic expression & casting Using Scanner class for input Important Note: All submitted assignments must begin with the descriptive comment block similar to the one shown below under Part 1, Program #1. It must contain your name and the other information illustrated. To avoid losing trivial points, make sure this comment header is included in every assignment you submit, and that it is updated accordingly from assignment to assignment. Part 1: Program #1 Compile and Run: (5 pts) Type the following code into a file called Expressions.java. After the program is entered, compile and run the application to make sure it works. Each invocation of println outputs an arithmetic expression. The first println command is followed by comment that shows the output and describe the operation that occur in the first expression. Complete the program by adding a comment after each println statement that describes all the arithmetic operations that occur when evaluating the expression that is printed. //*********************************************************** // Name: Faye Navabi // Title: Expressions.java // Author: Modified from an example in Big Java book // Description: arithmetic operations in Java // Time spent: 30 minutes // Date: 8/15/2017 //************************************************************** public class Expressions { public static void main(String[] args) { int a = 3; int b = 4; int c = 5; int d = 18; System.out.println(Math.sqrt(b));//a)2.0 it prints the square root of b System.out.println(Math.pow(a, b));//b) System.out.println(a + b / c);//c) System.out.println(++a);//d System.out.println(a++);//e) System.out.println(a + 1);//f) System.out.println(d % c);//g) System.out.println(d / c);//h) System.out.println(d + a / d + b);//i) System.out.println((d + a) / (d + b));//j) } } Note: The answers to each System.out.println (a through j) above should be typed in the block of comments in the Assignemnt1.java file. Do NOT submit this file only the answers are typed as block of comments in the file (Assignment1.java). Answers to a is provided in the code above. Program #2: Programming (15 pts) Overview: Write a complete Java program in a source file to be named Assignment1.java, that computes an individuals body mass index (BMI). Health professionals use this number to advise people about whether or not they are overweight. Given an individuals height and weight, we can compute the persons BMI, which is the weight divided by the square of the height and then multiply the result of the operation by the literal value 703. Here is the formula: BMI = weight in pounds * 703 / (height in inches * height in inches) Your program asks user for height in feet and inches, and weight in pounds. Then it computes the BMI. Example Execution: Below is a sample execution. Bold text indicates user input. What is your weight? 195 What is your height? Feet: 5 Inches: 10 Your current BMI is: 27.98 Implementation Details: You can assume that the user will always input positive values for weight and height. The user may enter zeros but not negative numbers. You may want to create variables for the following pieces of information: height (int) weight (double) bmi (double) constant 703- BMIVALUE You may use additional variables, and you are not required to create the ones mentioned above. This program should be implemented using only one class (called Assignment1) and should only contain one method (main). Additional Sample Output: What is your weight? 180 What is your height? Feet: 5 Inches: 10 Your current BMI is: 25.82 What is your weight? 130 What is your height? Feet: 5 Inches: 0 Your current BMI is: 25.39 For this and all subsequent assignments, provide a heading (in comments) described above and demonstrated in Program #1. Make sure your program is called Assignment1.java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started