Sometimes you need to generate a random number. In Java, the easiest way to do this is to invoke Math.random(). This method returns a value from [0 - 1) which means from 0 (inclusive) up to but not including 1 (exclusive). You can adjust the output by multiplying by a constant and then (int) casting the result, to lop off the decimal part.
Here are some examples and what they return:
Friday, October 7, 2011
Wednesday, October 5, 2011
More on tidy string building
I have edited the Building a tidy string post to show how to append additional text to the formatted string. Both screenshots reflect the version 2 source code.
Tuesday, October 4, 2011
Quiz #4 - results
Overall performance continues to improve! The class average this week was 82.6% and three students earned full credit.Grade distribution follows:
Homework 6 - SmallestNSquared.java
You are to complete exercise 4.12, p 148.You'll be finding the smallest integer such that its square is strictly greater than 1994. You must provide proof that your calculation is correct. The class name must be SmallestNSquared and it must be written as a console application.
Homework 5 - FootedBmiGUI.java
You are to complete exercise 3.6, p 107, modifying the program in listing 3.5 on pages 84 and 85.The class name must be FootedBmiGUI and it must be written as a GUI application. Instead of using pure numbers in your code, you must declare appropriately named constants. Follow the example in Building a tidy string to format your output nicely.
Monday, October 3, 2011
Exam #1 preparation
Your first exam, on chapters 1 through 4 of the textbook, is scheduled in class for two weeks from tomorrow. Next week, we will review the material for the exam and take a practice test. Keep an eye on the blog this week for test preparation suggestions. Programming problems on exams are often very similar to the end of chapter exercises.WebAdvisor - interval 2
Today is the end of the second WebAdvisor monitoring interval. Students with attendance issues, poor homework performance, and/or missing assignments should take this warning seriously.
Subscribe to:
Posts (Atom)