Starting from:

$35

KIT101 Programming Fundamentals Assignment 1 Solved

KIT101 Programming Fundamentals  Assignment 1
Background
You have a meal to eat. But should you consume it? Obviously if it’s solely chocolate or alcohol then the answer is probably ‘yes’. Obviously if it’s some kind of green vegetable or green meat (or in fact anything green) then the answer is most definitely ‘no’!

If you can eat it, should you? Well, not if it’s too hot or too cold — and not if there’s too much of it!  Everything in moderation after all (except green food).

 

You are to write a Java application program named AssigOne216.java which provides the user with advice as to whether their meal is edible or inedible and why. If it’s edible then the amount of food left over (if any) should be shown. The details (specifications) of this task are given below. Note that the correctness marks you receive for your program will depend on how well it matches this specification. If you decide to implement something that is more elaborate than specified, you should understand that:

•       There will be no marks awarded for the elaborations you have designed and penalties may be applied for confusing/extraneous code.

•       Your program MUST STILL meet the basic specifications given below.

 

The program is to determine whether the meal is edible or inedible and why. The user will be asked three initial questions:

•       The description of the meal to be consumed (which may be a multi-word answer which contains spaces).

•       The volume of the meal in millilitres (a whole number).

•       Whether or not the meal is at the ambient room temperature (of 22.0 degrees Celsius).  If the meal is not at room-temperature then the user should be asked for the temperature (as a floating point number).

 

The user may opt not to provide any information about meals at all.

 

NOTE: Part of the assessment of your program may be done automatically, so it is important that you follow the specification exactly, for example the questions must be asked in the order given and the method the user is given to indicate that they want to enquire about.

 

Algorithm
•       Firstly, the program should ask the user whether they would like to consume the food they have.  

•       If the user does wish to consume their food then  o The user will be asked to enter a description of the meal they have.

(Their entry may contain spaces and upper- and lower-case letters.) o The user will be asked to enter the volume of their food in millilitres (as a whole number).

o   The user will be asked to enter whether or not their meal is at roomtemperature (using a true or false value).

o   If the user indicates that their meal is not at room temperature then

§  They will be asked to enter the current temperature of their meal (a floating-point number value which may be positive, negative, or zero).

o   The program will then work out whether the meal is edible or not and what, if any food remains after the first 1500 ml is consumed...  Starting with the assumption that the meal is edible, if there is insufficient food to eat (i.e. 0 ml or less) then

§  the meal is inedible because there is not enough of it o Otherwise

§  If the meal is too hot (65 degrees or hotter) or too cold (–5 degrees or colder) then

•       The meal is inedible because of its temperature

§ Otherwise

•       If the meal is either “chocolate” or “alcohol” then o The meal is edible because it’s a favourite food

•       Otherwise

o If the description of the meal starts with “green” then

§  The meal is inedible because it is green o Otherwise

§  The meal is edible but for no special reason

o If the meal is edible  

§  The amount of food which remains after the maximum of 1500 ml is consumed is calculated.

§  The description of the meal, its volume, and its temperature should then be displayed to the user

§  The state (edible) of the meal should then be given together with the reason (see sample output).

§  The volume remaining should also be displayed (again, see sample output). o Otherwise

§  The description of the meal, its volume, and its temperature should then be displayed to the user

§  The state (inedible) of the meal should then be given together with the reason (see sample output).

•       After the meal’s contents has been considered the user will be asked if they wish to consider another meal. To analyse another the user must enter a line beginning with ‘y’ or ‘Y’ (for yes). The program should repeat until they enter a response commencing with a letter other than ‘y’ or ‘Y’.

•       The user will be shown a message saying how many meals were analysed.

 

Three example executions are shown below:

 

Would you like to eat the food you have? n 

 

0 meals were attempted. 

 

 

 

Would you like to eat the food you have? y 

 

Please describe the food you have: green beans 

What is the volume of the food you have (in millilitres)? 200 

True/False -- Is the food at room temperature? false 

What temperature is the food (in Celsius)? 50 

 

Your 200 ml meal of green beans, currently at 50.0 degrees Celsius is inedible because food contains something green -- yecccchhh! 

 

Would you like to eat more of the food you have? Yes 

 

Please describe the food you have: chocolate 

What is the volume of the food you have (in millilitres)? 30 

True/False -- Is the food at room temperature? true 

 

Your 30 ml meal of chocolate, currently at 22.0 degrees Celsius is edible because food is either chocolate or alcohol! 

There will be 0 millilitres of food remaining after you've eaten 

 

Would you like to eat more of the food you have? yep 

 

Please describe the food you have: alcohol 

What is the volume of the food you have (in millilitres)? 2000 

True/False -- Is the food at room temperature? false 

What temperature is the food (in Celsius)? 0 

 

Your 2000 ml meal of alcohol, currently at 0.0 degrees Celsius is edible because food is either chocolate or alcohol! 

There will be 500 millilitres of food remaining after you've eaten 

 

Would you like to eat more of the food you have? no 

 

3 meals were attempted. 

 

 

 

 

Would you like to eat the food you have? YES 

 

Please describe the food you have: beef steak 

What is the volume of the food you have (in millilitres)? 350 

True/False -- Is the food at room temperature? false 

What temperature is the food (in Celsius)? -10.5 

 

Your 350 ml meal of beef steak, currently at -10.5 degrees Celsius is inedible because food must be between -5.0 and 65.0 degrees to be consumed! 

 

Would you like to eat more of the food you have? y 

 

Please describe the food you have: water 

What is the volume of the food you have (in millilitres)? 100 

True/False -- Is the food at room temperature? false 

What temperature is the food (in Celsius)? 100 

 

Your 100 ml meal of water, currently at 100.0 degrees Celsius 

is inedible because food must be between -5.0 and 65.0 degrees to be consumed! 

 

Would you like to eat more of the food you have? y 

 

Please describe the food you have: biscuit 

What is the volume of the food you have (in millilitres)? 5 

True/False -- Is the food at room temperature? true 

 

Your 5 ml meal of biscuit, currently at 22.0 degrees Celsius is edible because of nothing special. 

There will be 0 millilitres of food remaining after you've eaten 

 

Would you like to eat more of the food you have? n 

 

3 meals were attempted. 

 

Planning
This program (like all programs) should be developed in stages, with each stage fully implemented and tested before the next stage is attempted. Here are some suggestions that should help with your planning and development of the program.

 

Write a program in a file with the correct name — put very simple code in it, for example just display a message such as “program starts”.

1.     Work out the types of variables that will be needed to hold the necessary information and write their declarations.  Some of the things that will be needed are:

•       a String entered by the user (for the description of the meal)

•       an int entered by the user (for the volume of the meal)

•       a boolean entered by the user (for whether the meal is at roomtemperature)

•       a double entered by the user (for the temperature of the meal)

•       a String for the description of why the meal is edible or inedible

•       a boolean to remember whether it is edible or inedible

•       an int for the volume of excess food

•       the char entered by the user to indicate they wish to enter more meal details

•       the count of the number of meal analyses undertaken (an int)

•       a Scanner object

2.     Work out what ‘constant’ values will be needed to be stored in the program; these can be implemented as final variables. Some of these could be:

•       the current room-temperature

•       the minimum and maximum temperatures for edible food

•       the minimum and maximum volumes that may be consumed

•       the favourite foods and the colour of the inedible food

•       the letters that allow the repetition of the program

3.     Work out how to use the Scanner class provided for this unit to read in values of different types entered by the user. NB you will need to mix calls of 

nextLine(), nextDouble(), nextInt(), and nextBoolean(). To do this effectively follow the latter three with calls to nextLine().

4.     At this stage you should be able to write a program that will do all the things that are needed to work out the result for a single meal.

5.     To allow the user to see more you will need another loop.  Think about what the loop will need and which loop (for, do, while) will be most appropriate:

•       initialisation

•       test (should this be before or after?)

•       body

•       update

 

Program Style
The program you write for this assignment must be in a single file called AssigOne216.java.

 

Your program should follow the following coding conventions:

•       final variable identifiers should be used as much as possible, should be written all in upper case and should be declared before all other variables

•       variable identifiers should start with a lower case letter and all variables should be declared at the top of the main() method (but after any constants)      every if and if-else statement should have a block of code (i.e. collections of lines surrounded by { and }) for both the if part and the else part (if used)

•       every loop should have a block of code for its body

•       the keyword continue should not be used

•       the keyword break should only be used as part of a switch statement

•       opening and closing braces of a block should be aligned

•       all code within a block should be aligned and indented 1 tab stop (or 4 spaces) from the braces marking this block

•       commenting:

o   There should be a block of header comment which includes at least

§  file name

§  student name

§  student identity number

§  a statement of the purpose of the program

§  date o  Each variable declaration should be commented

o   There should be a comment identifying groups of statements that do various parts of the task

o   Comments should describe the strategy of the code and should not simply translate the Java into English, e.g.

count = count + 1; // increment the count of the number of meals analysed and not:

count = count + 1; // add 1 to the count variable

What and how to submit 
What to submit
Paper submission
•       A signed cover page (blanks can be collected from the Discipline of ICT office or from the Discipline’s web site).

•       A print-out of the source code file for the program in landscape orientation. Your assignment will not be fully marked unless this is present.

Electronic submission 

•       Your source code file which must be named AssigOne216.java).

How to submit 
Paper submission
    Firmly staple together all of the required documents (with the signed cover page on top) and place them in the appropriate submissions box near the Discipline of ICT Help Desk.   

Electronic submission
    Upload your program file (AssigOne216.c) to the Assignment 1 Dropbox on MyLO.

Marking scheme 
Task/Topic 
Maximum mark 
Program submitted in form required 
 
Program submitted correctly 

Program compiles without error and runs to completion with test data 

Program operates as specified 
 
Prompts user for required information (in correct order)  

Reason for (in)edibility of meal is correct 

Handles food description correctly 

Handles volume correctly 

Handles temperature correctly 

Handles room temperature correctly 

User is asked whether they want to commence/continue 

Behaves correctly (i.e. repeats) if user enters line beginning y/Y 

Output is formatted properly 

Answer is calculated correctly 

Summary information correct at end 

Operates correctly when run multiple times 
 
Coding is correct 

Count is correct 

Program Style 
 
Uses final variables where appropriate 

Variables are declared only at the top of methods 

Does not unnecessarily repeat tests or have other redundant/confusing code 

Uses pre-existing methods (Scanner/String objects) 

Uses correctly the Java naming conventions 

Alignment of code and use of white space makes code readable 

Always uses blocks in branch and loop constructs 

Meaningful identifiers 

Header comments for the program (author, date etc) 

Each variable declaration is commented 

Comments within the code indicate the purpose of sections of code (but DO NOT just duplicate what the code says) 

Help and Hints
•       Read the specification carefully and make sure that you know what your program needs to do. Work out some pencil and paper examples. This is especially important for this assignment. The coding is not especially difficult provided that you know what the code needs to do.

•       Break the problem down into subtasks. For each of these tasks o Produce an algorithm before writing any code. o When you start to code add only a small amount of code at a time. o Compile and run to check that this part is working before proceeding. o Test thoroughly to see that the program you have written performs this task correctly.

•       You will waste a lot of your time if you do not follow a step-by-step method of solving a problem such as this. It is a mistake to think that this step-by-step method is slower than trying to tackle the whole problem at once. It never is.

•       Once you think you have completed your program, test it thoroughly to ensure it works correctly.  Repeat these tests if you make any modifications to your program.

•       DO NOT neglect your tutorial work in the unit to work on the assignment. Some of the tutorial activities may lead you to see what needs to be done in the assignment.

•       You may seek help with this assignment in normal consultation times for this unit or via email to your lecturer. Here are some hints to make best use of help.

o   Make sure you know (or think you know) what your problem is. o Have details of the work you have done so far and the progress you have made on hand when you seek help.

o   The more specific you can be in your request for help the more immediately useful the help is likely to be.

Plagiarism and Cheating: 

Practical assignments are used by the Discipline of ICT for students to both reinforce and demonstrate their understanding of material which has been presented in class. They have a role both for assessment and for learning.  It is a requirement that work you hand in for assessment is substantially your own.

Working with others
One effective way to grasp principles and concepts is to discuss the issues with your peers and/or friends. You are encouraged to do this. We also encourage you to discuss aspects of practical assignments with others. However, once you have clarified the principles, you must express them in writing or electronically entirely on your own. In other words you must develop the algorithm to solve the problem and write the program which implements this algorithm by yourself.  Any assistance should be provided by staff.

More products