Programming Fundamentals in Java

Module [203] - Java Iterative Statements

This module will explore Java's iterative statements and allow you to implement loops in your java programs.

  • Textbook Reading Assignments
  • The following sections of the textbook are assigned for this module.
    • Chapter #4 - Math Functions, Characters & Strings
    • Chapter #5 - Loops
  • Nick Parlante's Java For & While Loops
  • URL Link: Tutorial
  • This tutorial page, from the author of the JavaBat tool we are using, will provide you with a convenient summary of the textbook chapter.

Module Learning Outcomes

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

Tracing
Ability to read and trace Java programs leveraging conditional expressions and Iterative statement.
Implementing
Ability to write Java programs leveraging conditional expressions and Iterative statements.
Testing
Ability to develop tests, on paper for now, that are going to allow us to ensure Java programs leveraging Iterative statements and conditional expressions computes the results expected by requirements.
Debugging
Ability to troubleshoot Java programs leveraging conditional expression and Iterative statements.
Designing
Ability to design Java programs leveraging conditional expressions and Iterative statements.

  • A01 - Stats on positive & negative numbers
  • Video Link: YouTube
  • This exercise is #5.1 in the 11th & 10th editions of our text; it was #4.2 in older editions. Write a Java program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not countin zeros). Your program ends with the input 0. Display the average as a floating-point number.
  • A02 - Display Kilograms to Pounds Conversion Table
  • Video Link: YouTube
  • This exercise is #5.5 in the 11th & 10th editions of our text; it was #4.5 in older editions. Write a Java program that displays for every integer kilogram value between 1 and 199 the corresponding value in Pounds.
  • A03 - Find the best grade
  • Video Link: YouTube
  • This exercise is #5.8 in the 11th & 10th editions of our text; it was #4.8 in older editions. Write a Java program that prompts the user for a number of students to process. Then, your program will read the name and grade value for every one of these students. Your goal is then to track the best grade and display the name and grade of the best student.
  • A04 - Find the two best grades
  • Video Link: YouTube
  • This exercise is #5.9 in the 11th & 10th editions of our text; it was #4.9 in older editions. Modify the previous program so that it now displays the best two grades.
  • A05 - Display numbers divisible by 5 and 6
  • Video Link: YouTube
  • This exercise is #5.10 in the 11th & 10th editions of our text; it was #4.10 in older editions. Write a Java program which displays all integers between 100 and 1000 which are divisible by 5 and 6. Display 10 integers per line, each separated by a single space.
  • A06 - n square greater than 12,000
  • Video Link: YouTube
  • This exercise is #5.12 in the 11th & 10th editions of our text; it was #4.12 in older editions. Write a Java program that finds the smallest integer value n such that n squared is greater than 12,000

Each of the following links will lead you to a separate tutor applet. The tutors take usually 30 minutes to work through.

  • Problet #1 - Loops - while
  • URL Link: See Instructor Announcements
  • This Problet tutor will allow you to practice using Java while statements.
  • Problet #3 - Loops - do-while
  • URL Link: See Instructor Announcements
  • This Problet tutor will allow you to practice using Java do-while loops

Our first JavaBat exercises will focus on solving problems with strings without the help of loops. They are from the String-1 group of exercises from the JavaBat website

  • JB1 - First Half of a String
  • URL Link: firstHalf
  • Given a string of even length, return the first half. So the string "WooHoo" yields "Woo".
  • JB2 - Word matching the start of a String
  • URL Link: startWord
  • Given a string and a second "word" string, we'll say that the word matches the string if it appears at the front of the string, except its first char does not need to match exactly. On a match, return the front of the string, or otherwise return the empty string. So, so with the string "hippo" the word "hi" returns "hi" and "xip" returns "hip". The word will be at least length 1.
  • JB3 - Concatenating Strings
  • URL Link: comboString
  • Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on the outside and the longer string on the inside. The strings will not be the same length, but they may be empty (length 0).

The following exercises will require you to use loops & Strings. They are from the String-2 group of exercises from the JavaBat website

  • JB4 - Replacing * in a String
  • URL Link: starOut
  • Return a version of the given string, where for every star (*) in the string the star and the chars immediately to its left and right are gone. So "ab*cd" yields "ad" and "ab**cd" also yields "ad".
  • JB5 - Building a String
  • URL Link: repeatSeparator
  • Given two strings, word and a separator, return a big string made of count occurences of the word, separated by the separator string.
  • JB6 - Mixing Two Strings
  • URL Link: mixString
  • Given two strings, A and B, create a bigger string made of the first char of A, the first char of B, the second char of A, the second char of B, and so on. Any leftover chars go at the end of the result.

The following Homework focus on Math Functions, Charactes & Strings;

  • B01 - Finances: Payroll
  • This exercise is #4.23 in the 11th & 10th editions of our text.
  • B02 - Order Three Cities
  • This exercise is #4.24 in the 11th & 10th editions of our text.

The following Homework focus on Java Iterative Statements;

  • B04 - Displaying a Conversion Table for Miles to Kilometers
  • This exercise is #5.4 in the 11th & 10th editions of our text.
  • B05 - Displaying a Conversion Table for Pounds to Kilograms
  • This exercise is #5.5 in the 11th & 10th editions of our text.
  • B06 - Numbers divisible by 5 or 6, but not both
  • This exercise is #5.11 in the 11th & 10th editions of our text.
  • B07 - Largest n such as n cube is lesser than 12,000
  • This exercise is #5.13 in the 11th & 10th editions of our text.