Topic(s): Intro to Java; Java tools; primitive types, classes, & objects; control flow, methods, & parameter passing; input & output; strings, arrays, & lists; exceptions & handling; programming style
Related Reading: Chapter 1, and Sections 4.6, 4.7
To see the solutions for these Practice Problems, go to Solutions, and select the appropriate Chapter and Exercise number.
Odd numbered exercises at the end of Chapter 1.
You are allowed to submit your assignment via email, but if you choose to do so, you must bring a hardcopy of your assignment along with a completed cover sheet to the instructor at the next class. (Note: Do not email the instructor any .zip file attachments, as SLU's email may not deliver these emails, i.e. the instructor may not receive your email.)
Create a class with a main() method that computes an estimate for π based on Liebniz' formula for computing pi:
Create a class called SumTester that has a main() method which computes and prints out the sums of all numbers in the given ranges:
In the same class, create a method that computes the sum between a starting value, low, and an ending value, high, and returns that sum. Have main() call this method and print out the result for the following sums:
Finally, create a separate class, called SumNums, that has a constructor with input parameters for the low and high values.
In your SumNums class, you also need to create two other methods. The first is fullSum(), which returns the sum of all numbers between low and high. The second is skipSum(), which returns the sum of every other number in the range between low and high (i.e. it skips every other number). Have main() in the original class create instances of SumNums, and compute and output both the full sum and skip sum for the following number ranges:
Create a program that queries a user for names, then adds those names to an ArrayList of Strings. Once the user enters each name, have the program query the user for another name, until such time as the user enters a quit command like "done", "exit", or "quit".
Once the user has entered all desired names, use the Collections.sort() method to sort the ArrayList, and then print out the final names in sorted order.
Note 1: You'll want to use String's equals() method for comparison -- the "==" operator doesn't provide the comparison you typically want with strings... see String comparison in Java for more info.
Note 2: Sections 1.10 and 1.11 are particularly helpful for this problem.
Following is the start of a program (similar to HelloWorldFrame) for administering computer-based quizzes to students: QuizGUI.java
Given this starting point, modify the program so that it does the following:
Note: You should supply at least 5 of your own questions. Looking at the code, you should see that they don't need to be True/False, so at least a couple of your questions should be different.