The Cronut Assignment

Created Tuesday 03 July 2018

(for your review, here is the example code from last class, exactly as it was at the end, POSSIBLE ERRORS AND ALL) - hero OOP!

MAY WE ALL BE CRONUTS.


PART A


We will be writing part of a (completely fictional, but hey) interactive survey, and we will be collecting data. We want to partially anonymize it, so we're going to "code" for certain groups. So first, the class PROPERTIES: (aka, the data we need to collect)

- first name
- last name
- age
- income

ALL these will be "protected" in order to use OOP in its intended way.

Now, some of this data we can keep secret and others we can share, so you will write the following methods:

AGE:
0-20 is "Blue"
21-40 is "Red"
41-60 is "Green"
60 and older is "Yellow"


INCOME
0 - 10,000 is "Biscuit"
10,000 - 50,000 is "Muffin"
50,000 - 150,000 is "Toast"
150,000 and above is "Cronut"


Write a method (or perhaps two might be easier, your choice) that assists in telling the user their code; e.g. Jethro Jones who reports as a 34 year old with a 25,000 income is a "Red Muffin." You do NOT need to write "getters" for these since (at least for now) we don't want to reveal them.

At this stage, you may want to test your code in a similar manner that we did in class (after all, the writing of the class ultimately does nothing without calling the objects/methods); i.e. simply "set" and "get" a user manually through assignment to ensure that the thing works.

Post this file in your html root directory as "cronutclass.php"

PART B


NEXT, utilizing your class, create an interactive form that queries the user for their first and last name, age, and income, with a submit button.

Upon pressing the submit button, the user should recieve a confirmation something like the following:

Thanks Jethro!
Pardon me, I mean Dr. Jones.
Your code symbol is Red Muffin

The form can be two pages. Also, for input - names will obviously have to take a text box. For the age and income, there is more than one way to accomplish this — remember our form types.

This can be accomplished with one, two, or three logical pages. Let's go with three:
A "classes" page that contains only class definitions. You can probably just copy the above, and remove other code. Let's go with convention and call this "cronut-classes.php"
A "form" page that has your form. This can be pure html, so call it either "cronut-form.html" or "cronut-form.php"
Finally, you'll have a page that shows the output, so call it "cronut-output.php." THIS PAGE WILL NECESSARILY NEED TO "INCLUDE/REQUIRE" cronut-classes.php.


A tip. You don't have to do this in the order intended, it may be possible or useful to write the form and output generator *first* and then later rewrite it as OOP. This might sound like a pain, but think of it as similar to drafts in prose writing — sometimes you throw out what you've already written because the new stuff is better.

Good Luck! Watch this space, I'll field questions and perhaps provide more guidance if needed.

PART C



Part B doesn't actually do anything with the above information; let's get this thing actually doing something.

First, let's set up a better convention for our real "app." Instead of what we have above (don't delete it!) do the following.

Under your html root directory, create a new directory called "cronut." You'll have the following files (and, of course, feel free to copy from your work above.)

./cronut/classes.php - this will contain our class(es_
./cronut/index.php - this will be the "main" landing page, which should prompt for information from the user.
./cronut/output.php - this will be the target of the form action, which will deliver the confirmation as above AND
./cronut/data.txt  - this will be where our data is stored, specifically:

Along with the same output of part B, ALSO store this data in the data.txt file. We went over a number of ways to do so, but since our data would work well as a table, lets use a simple CSV (comma separated values) format. Each time "index" is run, it should both give a confirmation to the user and append the latest data to the "data.txt" file.

*Note — you may find it useful or necessary to change the protection level of some of your methods (e.g. from or to public or protected). This is fine. Please, however, always keep your ATTRIBUTES protected.


PART D


One more file:
./cronut/backend.php

The idea is that this is for the survey creator. Present ALL the data contained within data.txt in the following way (see the above note about changing method protection levels)

I suspect that most of this should be self-explanatory? Good luck!
















Backlinks: FSU Courses:LIS5367