Programming Fundamentals in Java

Module [201] - Java Primitive Data Types

This module will get you started working with the Java Programming language and review the main data types of this language, their applications, how they are represented and their limits.

  • Textbook Reading Assignments
  • The following sections of the textbook are assigned for this module.
    • Chapter #1 – Introduction to Computers, Programs & Java
      • Review since we already dealt with parts of it in [101]
    • Chapter #2 – Elementary Programming

Module Learning Outcomes

In this module, you will develop further your programming skills as follows;

Tracing
Ability to read and trace Java code that assigns values to variables and process arithmetic computations on their values.
Implementing
Ability to write Java code performing specified computations on variables and their values.
Testing
Ability to develop tests, on paper for now, that are going to allow us to ensure a program computes the results expected by requirements.
Debugging
Ability to troubleshoot variables assignments and arithmetic computations.
Designing
Ability to design computation steps on variables and their values that lead to a specified result.

Unlike modules [101], [102] & [103], the exercises for our modules will, from now on, be taken from the textbook. Please note that the exercises are at the end of the chapters in the "Programming Exercises" subsection. While you might hear a different number in the videos, due to the recording being done based on a previous version of our text, you will find the number for the latest edition below.

  • A01 - Compute the volume of a cylinder
  • Video Link: YouTube
  • This exercise appears as #2.2 in the 11th & 10th editions of our textbook. Write a Java program that reads in the radius & length of a cylinder and computes the area and volume using the following formulas;
    • area = radius * radius * pi
    • volume = area * length
  • A02 - Finances: Compute tips
  • Video Link: YouTube
  • This exercise appears as #2.5 in the 11th & 10th editions of our textbook. Write a Java program that reads a value for a check and the gratuity rate. You will then compute the gratuity and the total and display them. E.g. a $10 check with a gratuity rate of 15 percent will result in a gratuity of $1.5 and a $10 total.
  • A03 - Sum digits in an integer
  • Video Link: YouTube
  • This exercise appears as #2.6 in the 11th & 10th editions of our textbook. Write a Java program that reads an integer between 0 and 1000. It will then sum all the digits of this integer. E.g. for a value of 932, the program would display that the sum is 14.
  • A04 - Manipulating characters as integer values
  • Video Link: YouTube
  • This exercise was #2.7 in the 10th edition of our text. Since it is no longer available in the 11th edition, please see description below. Store in a char variable a character representing a lowercase letter. Use arithmetics to transform it into its uppercase counterpart. Display both the initial and transformed characters.

As previously discussed, we are going to use Amruth Kumar's Problets Intelligent Tutoring System to help you practice some aspects of the Java syntax.

As a reminder from our "Welcome Aboard" section, here is the link you used during week #1 to test that your system was able to run Problets.

  • Test Problets.org
  • URL Link: http://problets.org/about/topics/features/index.html
  • Use Internet Explorer to go to the above URL. Make sure you have already installed the Java JDK on your system before to attempt this. You may then click any of the "Java" buttons to check whether your system is able to run Problets
  • Problets Troubleshooting
  • File Link: PDF
  • If you have issues running problets from your web browser, take a look at this troubleshooting guide. It was authored by Raul Estrada Ballesteros in spring 2018.

When you have re-tested your system, watch the following video on how to work with Problets.

  • How to work on Problets
  • Video Link: YouTube

You will then find below the name of the specific Problets you need to work on in order to get practice credit. Please refer to your instructor's announcements for details on how to submit a proof of your practice.

Since each course has a separate site, you will have to use a specific link for this semester. The link will be posted by your instructor. Using any other link will prevent you from getting credit for your practice efforts. Each of the following tutors usually take 30-45 minutes to work through.

  • Problet #1 - Expression Evaluation - Arithmetic
  • URL Link: See Instructor Announcements
  • This Problet tutor will allow you to practice evaluating Java arithmetic expressions.
  • Problet #2 - Expression Evaluation - Assignments
  • URL Link: See Instructor Announcements
  • This Problet tutor will allow you to practice evaluating Java assignments.

Unlike modules [101], [102] & [103], the exercises for our modules will, from now on, be taken from the textbook. Please note that the exercises are at the end of the chapters in the "Programming Exercises" subsection. The numbers below refer to the latest edition of the textbook.

  • B01 - Convert Celsius to Fahrenheit
  • This exercise is #2.1 in the 11th & 10th editions of our text. Write a program which reads a temperature expressed in Celsius degrees from the console. You will store this value as a double. Display the conversion of this value into degree Fahrenheit by applying the following formula;
    Fahrenheit = ( 9 / 5 ) * Celsius + 32
    
  • B02 - Convert Feet to Meters
  • This exercise is #2.3 in the 11th & 10th editions of our text. Write a program which reads a distance expressed in feet from the console. You will store this value as a double. Display the conversion of this value into meters knowing that one foot is 0.305 meters.
  • B03 - Convert Pounds into Kilograms
  • This exercise is #2.4 in the 11th & 10th editions of our text. Write a program which reads a weight expressed in Pounds from the console. You will store this value as a double. Display the conversion of this value into Kilograms knowing that one pound is 0.454 kilograms.
  • B04 - Physics: Acceleration
  • This exercise is #2.9 in the 11th & 10th editions of our text. The average acceleration is defined as the difference in velocity divided by the amount of time between the two measurements;
    a = ( v1 - v0 ) / t
    
    Write a program which reads two velocity values from the console as double. The starting velocity v0 and the ending velocity v1 will be expressed in meters per second. Your program will then read a duration t expressed in seconds. You will use these values to compute and then display the average acceleration using the above formula.
  • B05 - Physics: Runaway Length
  • This exercise is #2.12 in the 11th & 10th editions of our text. Given an acceleration value a, in meters per second squared, and a take off speed v, expressed in meters per second, the minimal runaway lenght needed for the plane to take off, expressed in meters, is given by the following formula;
    length = ( v * v ) / ( 2 * a)
    
    Write a program which reads, from the console, double values for v and a then display the minimal runaway length.
  • B06 - Finance: Compound Values
  • This exercise is #2.13 in the 11th & 10th editions of our text. Given a monthly deposit, expressed in dollars, we want to compute the compound value after 6 months. We will base our computations on a 5 percent annual interest rate which corresponds to a 0.05 / 12 = 0.00417 monthly interest rate.
    We start with deposit dollars in our account. The value after the first month will be given by the following formula;
    balance = deposit * (1 + 0.00417)
    
    We may now update our balance again for the 2nd month as follows;
    balance = (balance + deposit) * (1 + 0.05 / 12)
    
    The same formula may be applied repeatedly to our balance in order to get the balance for the next months.
    Write a program which reads from the console a double value for the monthly deposit, then displays the balance for each months. Please note that we will not use a loop since this module did not introduce them yet; instead simply apply the formula several times.