Application Project for Java Programming
From The Oracle Internet Academy Curriculum
Final Project

Your Vote Counts

Mary Roberts is a senior who is always coming up with grandiose ideas that most of the class laugh off with an “in your dreams.”  She once tried to get the school board to include skateboarding as a requirement in the physical education program.  And then there was a time when Mary proposed to have the AP Computer Science class try out for “The Real World”. 

The more we put down Mary’s ideas, the more encouragement she gets from Mr. Garcia, our AP Computer Science teacher.  Mr. Garcia is forever telling us about these kids who revolutionized the entire computer industry when they weren’t much older than us.

For example, twenty- five years ago, Larry Ellison saw an opportunity other companies missed – a concept for a database that no one else appreciated.  He and his partners saw the potential and built it into Oracle Corporation, the biggest database software developer in the world.  And then Mr. Garcia always, follows the Oracle story by telling how Bill Gates started Microsoft when he was still a teenager, not to mention the story about Steven Wozniak and Steve Jobs, two high school buddies who started Apple Computer in their parents’ garage.

Don’t get me wrong.  They’re great stories and I always bait Mr. Garcia into retelling them whenever I’m just not quite ready to submit homework.  But nothing like that could happen to anyone in my AP Computer Science class.

Of course, Mary sees things differently.  Mary’s philosophy is, why not?  Why can’t she build the next computer to revolutionize the industry?  Why can’t she write a program that is useful to a big corporation?  Why can’t she come up with an idea that rivals those of Oracle and Apple Computer?

In fact, Mary likes to run around quoting Larry Ellison: “When you innovate, you’ve got to be prepared for everyone telling you you’re nuts.”

And Mr. Garcia totally agrees with her.  He has a point.  Programs used by big corporations are written using the Java programming language, the same language that Mr. Garcia is teaching the class.  I guess when you look at it; Mary and Mr. Garcia might be onto something.  Those programs contain the same if statements, String objects, classes, and other syntax that we write in our programs. 

One day, Mary came up with this really way-out idea.  She thought high school students should voice their opinions on current affairs each week on the World News Network (WNN).  Mary wrote to WNN with her idea and said our AP Computer Science class would write a java program that collected votes from our student body, which she’d forwarded to WNN.  Actually, Mr. Garcia came up with the idea that our AP Computer Science class would write the program.

Weeks passed and even Mary forgot about her idea, but then her mom showed her a letter that arrived at noon.  The return address was WNN.  WNN!  I’d drop if WNN ever responded to my letter.  But the letter didn’t excite Mary.  Companies were always sending Mary official-looking letters that basically said, “Loved your idea, but not right for us.  Keep up the good work.”

However, this letter was a bit different.  WNN did write “loved your idea” but didn’t say “not right for us”.  In fact, WNN countered Mary’s idea proposal with one of their own.  This was a jaw-dropper that had both Mary and her mom rereading the letter over and over again. 

Yes, they agreed with Mary that high school students should have a stronger voice and that Mary’s weekly surveys were a good way for people to make their voices heard.  WNN proposed to give each student who worked on the survey program a grant toward his or her college fund and give a grant to our school to fund new computers for our AP Computer Science Class.

But there was a catch.  The class had to write the survey program.  The survey program had to work perfectly.  And if we succeeded, WNN planned to distribute the program to all high schools that participated in the survey.

Part I:  Writing a Program Outline

The AP Computing Science class was ecstatic when Mary broke the news.  Writing a Java program for WNN and getting paid too!  Mr. Garcia was just as excited as Mary was; but more contained.  He just couldn’t wait to burst out and blab the secret.

  “Is it true, Mr. Garcia?” 

  “Yes, I also received a letter from the public relations staff of WNN.  They want the class to build a survey system so high school students can vote for their favorite WNN performer.”  You could see how proud he was of Mary and of our class.

   “I discussed the project with Dr Allen, and she is allowing us to substitute the WNN project for our regular lessons for the remainder of the term.  This means that we begin the project today!”

 “How do we start this project?” Julian cautiously asked.

“Let’s see,” Mr. Garcia answered as he took up his favorite position sitting on the corner of his desk.  “The WNN deal requires the class to design and write the program without any help form outside the class.  So where should we begin?”

“Well,” Sherry paused.  “We’ll at least need to know how the  program is going to work.  I mean, how can we be expected to write the program without knowing what WNN wants?”  Sherry asked a bit sarcastically.  “I mean, what’s going to be on the screen?  What are the kids expected to type?”

    “These are good questions, Sherry. Where are you going to find answer to those questions?”

    “I guess we need a plan; an outline that describes how the program is supposed to work.”

     “Why don’t we begin with an outline?”  Mr. Garcia went to the board and wrote:

  1. Display
  2. Prompt
  3. Input
  4. Processing
  5. Output

   “What happens when someone starts the program?”  He looked back toward the class.

    “Something appears on the screen.”

    “Correct, Mary.  So this means we need to come up with something to show on the screen when the program begins.”  He pointed to the first item on the board.  “What’s next?”

    “We have to tell the person taking the survey to type something.”

    “So you’re telling me that you need to decide how to prompt the user to enter something.”  He point to the next item, “Keep going.  What happens next?”

    “The program does something with the input.”

    “Good!  It sounds like we’re coming up with a plan.”  Mr. Garcia stopped to think.           “So I think you’re saying the information entered by the user needs to be processed.”

   Mr. Garcia always had a way of correcting you without embarrassing you in front of the whole class.

    “And the last thing?”   His eyes focused.  “Sherry.”

    ”The program displays the result of the processing.”

    “I’ll buy that!”  Mr. Garcia dropped the chalk and dusted the chalk dust from his hands.  “Now that you have the outline for the project, write specifications for the programs.”

Assignment

Before you begin writing the code, you need to have a plan.  Use the elements from Mr. Garcia’s outline – display, prompt, input, processing, and output – and write an outline that will describe how your Java application will work.

Part 2:  Displaying the Questions and the Menu

We had to write a complete Java application that had to work perfectly – otherwise; no WNN and no money.  The class was baffled as first.  We had never really built a real program that would be used by a major company.

However, once we talked about how we want the program to work, we soon learned that we knew a lot.  The more we talked, the more Mr. Garcia’s outline made sense, and soon pieces of the WNN survey program began to fit together.

            “Okay, what’s your next step?”

            He glanced around the room.  Dead silence again as everyone went out of their way not to make eye contact with Mr. Garcia.  “Come on.  The hard part is over.  You know how the program will perform.  Now you simply need to write the code.”

            Yeah, simply write the code.  There’s nothing simple about writing code. 

            “I guess we begin with the first thing that we want the program to do,” said Bob.

            “So what’s the first thing you do when you write a Java program?”

            “Create a skeleton of a class.”

            “Do you know how to do that?”

            “Sure.”

            “How do you print text to the screen?”

            “System.out.println( ) or JOptionPane”

            “Right!  Now suppose you want to store the text in memory before you display it?”

            It was like a sledge hammer hit everyone in the class all at once.  You know the feeling.  You spend half the class wondering what on earth the teacher is talking about and then it clicks.  Pow!  Pieces fall into place and you’re a genius again.  Well, that’s what happened.

            We knew how to program, and we knew what we wanted displayed on the screen.  Now we just needed to write the first screen that will be displayed.

            “We need to create an object and variables and initialize them.”

            “Sounds like you know what to do next.  Go do it!”

Part 3: Responding to Menu Selection

            “Yo! Mr. Garcia! Over here!  We need a little help.”

            “What’s the problem Paulie?”

            “We got the menu displayed, but it’s not working the way we thought it would work.  There’s not keyboard read, and you have to restart the program every time you want to choose an item from the menu.”

            “That’s right, so how are you going to fix that?” Mr. Garcia remarked after quickly glancing at the program.

            “Let’s think through this problem together.  What is the smallest problem?” said Mr. Garcia.

            “Reading the menu select from the keyboard.”

            “What’s the simplest way to do that?”

            “With System.in.read().”

            “Is that the only way you know how to do that?”

            “No, we can use JOptionPane or a BufferedReader

            “Okay, so what’s the next problem?” said Mr. Garcia.

            “We have to know what the user selected” said Mary.

            “How can we do that?”

            “With an “if” or “switch” statement!” the class shouted!

Next, the program will need to show something on the screen to respond to each menu selection, and refresh the screen with the menu after you display a response on the screen.  You want the next person to be able to make a selection from the menu without restarting the program.  Also, there has to be a way to quit the program.   Each separate function should be in a method

Part 4: Tallying the Votes

Create a method to tally the students’ votes and the totals are displayed for each menu item to tally votes.

Part 5:  Writing an Opinion on the Command Line

Create a method that enables someone to either display the default question and the list of options on the current affairs issue of the week on the menu or enter a question and possible opinions at the command line.

Part 6: Incorporating Inheritance into the Program

Create a new class that contains the data used to hold the totals of votes for each item, then inherit this capability in another class.  Remember Inheritance is when a subclass inherits data and methods from a SuperClass.