CS173: Intro to Computer Science - Introduction to Boolean Expressions (3 Points)

Developed by Professor Tralie and Professor Mongan.

Exercise Goals

The goals of this exercise are:
  1. To become familiar with the basic structure of a Java program
  2. To write a Java statement
  3. To declare a variable
  4. To manipulate a variable with arithmetic statements
  5. To write a compound boolean expression to verify a numeric range
  6. To check the value of an imprecise floating point value
  7. To explain that a floating point value is represented imprecisely with a discrete binary representation
Modify the Driver.java file to determine if the circumference of a circle is approximately equal to a floating point value.

Enter your Ursinus netid before clicking run. This is not your ID number or your email. For example, my netid is wmongan (non Ursinus students can simply enter their name to get this to run, but they won't get an e-mail record or any form of credit).

Netid
Clicking Run below will check your work and, if it passes, will submit your work automatically. You must be connected to the VPN for submission to be successful! You will receive a copy of your code via e-mail, so you'll know that it was submitted if you receive that e-mail! VPN access requires Multi-Factor Authentication, which sends you a code when you log into the network. Instructions on configuring these for your account can be found here.

Driver.java

public class Driver { public static void main(String[] args) { /* Don't change these! */ float diameter = 6.5; float pi = 3.14159; /* TODO: Declare a floating point variable circumference, and set it equal to pi * the diameter */ /* TODO: Print the circumference of this circle */ /* The true circumference is 20.420335, which you can verify on your calculator. But you might get something slightly different here! Why? */ /* TODO: Declare a boolean variable called isApproximatelyEqual, whose value is true if the circumference is "approximately equal" to 20.420335, by checking if it is greater than a nearby value like 20.42 and smaller than a nearby value like 20.43. */ /* I'll print the value for you - don't change this! */ System.out.println(isApproximatelyEqual); } }
Driver.main(null);

Output