03-Week.docx

advertisement

Week 03 assignment

We will start with the WinIO.java example we used in class.

Notes:

0.

You can’t switch on an object or string, so note the underlined changes in 2 and 3.

1.

Your name should appear in the title bar of the window, as above

2.

We should use an “if … else if … else if … else” structure to decide which button was pressed.

3.

The first button should be labeled “Figure it out”, and it should determine what to do based on the contents of the first text field. You should use switchcase here. Hint: use myChar=s1.charAt(0) to put the first character in a char variable named myChar. See book example 3-13 on p 153. a.

If the field has a one-character string in it reading ‘A’ or ‘S’ or ‘s’, etc, (Ignore case), then the output should be the sum of the second and third fields, formatted to the closest ten-thousandth. b.

If the field has a string in it reading ‘P’ or ‘M’ or ‘m’, etc, (Ignore case), then the output should be the product of the second and third fields, formatted in scientific notation, with 6 significant figures shown. c.

If the field has a string in it reading ‘D’ or ‘Q’, then the output should be the ratio of the second and third fields, formatted in to the closest millionth. d.

If the field has any other contents, the output should be “Try again, buddy!”

4.

The second button should print the output “I’m OK” if the average of the three fields is in the interval (4,25] , and “No way, Jose!” otherwise. Button should be labeled “Interval”.

5.

The third button, labeled “Ethelred”, will print out “Wow” if the sum of the three numbered fields is very close to an integer. Very close means within 1 millionth of a whole number. It should output “Nope” for a number that is not near an integer, as described above. You get to choose if…else or find an absolute value function.

The .java file should be uploaded into the Angel dropbox for it.

Download