Difference between revisions of "Ifless Grade Calculator"

From CompSciWiki
Jump to: navigation, search
(further clarification of the problem)
m (grammar edit in by students)
Line 36: Line 36:
 
|SideSectionTitle=...by students
 
|SideSectionTitle=...by students
  
|SideSection=Mike Domaratzki, my 1010 professor, asked our class this problem on the second week of class. Of about 100 students, only 2 of us solved it. I remembered sitting through my class after 1010, furiously trying to solve the problem by hand. When I coded the program up, it took me an hour to debug. When I finally got it working, the sense of accomplishment was overwhelming.
+
|SideSection=Mike Domaratzki, my 1010 professor, asked my class this problem on the second week of class. Of about 100 students, only 2 of us solved it. I remembered sitting through my class after 1010, furiously trying to solve the problem by hand. When I coded the program up, it took me an hour to debug. When I finally got it working, the sense of accomplishment was overwhelming.
  
 
This is a difficult problem, one the would probably stump many fourth year students. Even though I know the trick for solving this problem, adding the plus grades was a bit difficult for me as well.
 
This is a difficult problem, one the would probably stump many fourth year students. Even though I know the trick for solving this problem, adding the plus grades was a bit difficult for me as well.

Revision as of 14:46, 9 April 2010

Back to the Program-A-Day homepage

Problem

Sunday Stumpers are the Sunday New York Times Crossword Puzzle of Program A Day. The problems are intentionally difficult, and the average student probably won't be able to get the whole solution by themselves. They will never contain anything that the students haven't learned, but they may apply things the students have learned in unorthodox ways. The solution will contain several hints and the actual code.

Next week you are going to be learning conditional statements (like if statements). This will allow you to make much more powerful programs. One problem that you are going to be asked to do next week, is to make a program that converts number grades into letter grades. Technically, it is possible to write this program without a single if statement.

Create a program that will allow the user to enter in a decimal letter grade, and will output the letter grade. The number grade should be entered using consecutive JOptionPane.showInputDialog, and the result should be given using System.out.println. Assume valid inputs. Don't use ifs, loops, arrays or anything else that have not yet been discussed.

The grades breakdown is as follows:

  • F: less than 50%
  • D: at least 50%, less than 60%
  • C: at least 60%, less than 70%
  • B: at least 70%, less than 80%
  • A: at least 80%

If you can get that working, then add plus grades:

  • F: less than 50%
  • D: at least 50%, less than 55%
  • D+: at least 55%, less than 60%
  • C: at least 60%, less than 65%
  • C+: at least 65%, less than 70%
  • B: at least 70%, less than 75%
  • B+: at least 75%, less than 80%
  • A: at least 80%, less than 90%
  • A+: at least 90%

Don't worry about plus grades until you have normal letter grades working


You will need the following:

 

...by students

Mike Domaratzki, my 1010 professor, asked my class this problem on the second week of class. Of about 100 students, only 2 of us solved it. I remembered sitting through my class after 1010, furiously trying to solve the problem by hand. When I coded the program up, it took me an hour to debug. When I finally got it working, the sense of accomplishment was overwhelming.

This is a difficult problem, one the would probably stump many fourth year students. Even though I know the trick for solving this problem, adding the plus grades was a bit difficult for me as well.

Solution

Hint 1: You can increment and decrement char values, just like you can ints

Code

Solution Code

Back to the Program-A-Day homepage