Development of a simple menu driven program

Assignment Help JAVA Programming
Reference no: EM13825185 , Length:

For this assignment you will be provided with incomplete sample starter code that you can modify and build upon. Your task will be to carry out the design, analysis, coding and testing to add several additional features to this sample code. You are expected to fully comment the provided code as well as your own code. The sample code provided has some minor issues that mean that although the code compiles it does not run as required.

Project Specification

The program that is to be developed should enable the entry of data from a short survey and to provide the user with some short reports on this data.

The data to be entered is from a survey and initially includes the following information:

• Gender - male, female, other or unspecified

• Preferred hand - left, right, both

• Super power - invisibility, super strength

• Life preference - famous, happy

The program should present the user with a menu that provides the following functionality:

1. Input data
2. View data
3. View report and graph
4. View basic statistics

Further details on functionality are provided in the task specifications provided below.

Part A - Code Comprehension

Your task is to first answer some questions testing your comprehension of the partial solution. Use the sample code provided in StarterCode.java to answer the following questions. Include the answers in your assignment submission.

1. The code provided does not contain any comments.

a. Briefly explain why comments are important in code.

b. Update the code provided to include comments - include a copy of the commented code starter code in your assignment submission.

2. Identify all of the lines of code within the program that are associated with obtaining user input. This can be done by either copying the lines into your answers or highlighting the lines within the code.

3. The variable finished should be used as the condition for the while loop.

a. Briefly explain the purpose of the variable finished.

b. What value will it have when the while loop is initially entered?

4. Run the program. When the menu is presented enter 2 as the selected item.

a. What is the output of the program to the console? Why are all the values 0?

b. Briefly explain how would you should alter the code below so that it displays an appropriate prompt, rather than "Enter Response 1" for each loop:

case 1: System.out.println("Menu selection 1");
for(int i=0;i<surveyResponses.length;i++){
System.out.println("Enter Response 1");

5. Identify the lines that would need to be altered so that the menu is controlled by a do-while loop rather than the while- loop and provide the new lines of code required

6. Currently a switch-statement is used within the program to handle the different menu options. What other program structure could have been used?

7. Run the program.

a. use the following table to test the code provided:

Menu Selection

Expected

Actual

Notes

1

Displays "Menu selection 1" and prompts the user for the responses for gender

Displays "Menu selection 1"

As expected

2

Displays "Menu selection 2" and contents of the array for each student

 

 

3

Displays "Menu selection 3"

 

 

4

Displays "Menu selection 4"

 

 

5

Exits the program

 

 

-1

Error

 

 

-6

Error

 

 

b. Briefly outline the changes would you would need to make to the program so that it handles the menu entries correctly and exits the program when the user enters menu selection 4. Note: You do not need to make the changes in the code for Part A.

8. With the program an array has been used to store the data. Currently the code has two lines declaring the array, one that has been commented out.

a. Briefly explain both of the lines of code used to declare arrays.

b. Briefly explain why the programmer would include the declaration that has been commented out.

Part B - Program Analysis, Implementation and Development

It is suggested that you design, implement and test each of detailed below in order - completing each section completely and correctly before proceeding to the next. For each stage, with the exception of stage 1, you should:

1. design a solution in the form of pseudo-code to carry out the required task - include this pseudo-code as part of your project documentation, clearly indicating which stage it belongs to;

2. perform a desk check of your logic - if you find any problems with your pseudo-code you should redesign and retest;

3. implement the stage - update the code so that it implements the algorithm you have designed - at the end of each stage listed below save a copy of the code that has been developed and name each file appropriately;

4. test the stage - ensure that before moving onto the next stage of development that the program works and that there are no logic or runtime errors

Your code should use appropriate programming standards and be well documented/commented. You are permitted to discuss the sample program with your peers in order to understand it. However, you must ensure that you complete this section individually. It is expected that no two students will have the same program.

Development Stages

1. Update the code so that it:

a. includes at least two new super powers and two new life preferences;

b. includes at least 5 new responses in the test data that has been hard coded into the array;

c. exits the program when the user enters 4 for exit;

d. handles case 2 appropriately (ie does not fall through to case 3); and

e. displays an error if the user enters an incorrect selection from the menu.

2. Update menu item 1 case so that:

a. the response number is displayed correctly when prompting the user to enter data - this should start at 1;

b. the program prompts the user for the survey results to be entered for each respondent and stores the data into the correct positions within the array. For example:

Gender (1=Male 2=Female 3=Other 4=Unspecified) :
Left or right handed (1=Left 2=Right 3=Both):
Super power (1=Invisibility 2=Super strength 3=...):
Life preference (1=Famous 2=Happy 3=....):
Age (in years):

3. Update menu item 2 so that it displays all of the raw data that is stored in the array. For example:

Num

Gender

Lefty?

Power

Life

Age

0

0

0

0

1

29

1

1

1

1

0

20

Etc..

 

 

 

 

 

4. Update menu item 3 -.display at least one graph using the data that has been entered. For example you might display a histogram of the genders or super powers. Within your documentation you should design and briefly explain why you have decided to design that particular graph.

5. Update menu item 4 so that it displays a short report on the results. In your documentation you should provide a design the report and a brief explanation of why your report has been designed that way. Your report must include at least the following:

a. The age of the oldest or youngest respondent(s)
b. The average age
c. The super power that was the most or least popular

6. Data validation - add code to validate any data entered by the user. For example: for menu item 1 the data for gender should be validated so that only the values between 1 and 4) will be stored by the program; if an invalid test score is entered the user should be re-prompted to enter a new value until a valid score is entered.

7. Final Challenge: Complete this only after you have completed all of the tasks have sufficient time. Copy of the code into a new file and break the program down so that it utilises methods to handle each of the menu items.

Part C - Testing

You should be testing your program as each stage is completed, and again once the program is complete. You should document the testing data, process and results (e.g. in the form of a table) and include this within your project documentation. Your mark for this section will reflect the thoroughness of your testing and the quality of your documentation.

Reference no: EM13825185

Questions Cloud

Explain the contract law that the court applied : Discuss the major issues addressed in the case you found. Explain the contract law that the court applied to the case and why. Then, determine at least one action in drafting the contract that either company to the dispute could have taken to avoi..
What is the marginal revenue : Monopoly a) Marginal Revenue A single seller of a video game console faces an aggregate demand of P (Q) = 500 -Q/2000 i. What is the total revenue function? ii. What is the marginal revenue?
Maintaining optimum inventory problem : Maintaining optimum inventory Problem
Define the production possibilities curve : Define the production possibilities curve in your own words.Could a nation's production possibilities curve ever shift inward? What are TWO factors that may cause this to occur?How can an economy achieve points that are outside the production possibi..
Development of a simple menu driven program : Identify all of the lines of code within the program that are associated with obtaining user input. This can be done by either copying the lines into your answers or highlighting the lines within the code.
Calculate price elasticity of demand for price of a product : The problem belongs to Economics and it is explore about using midpoint method for calculating the price elasticity of demand for the price of a product.
Explore the lemons problem : The questions explore the lemons problem with a third quality level, intermediate, whose repair costs are $500. Hence a buyer values this quality at $2,700 and a seller at $2,200.24.14 If each quality level is just as prevalent in the population, sho..
What amount should be reported in the balance sheet : Palmiero purchased a patent from Vania Co. for $1,500,000 on January 1, 2010. What amount should be reported in the balance sheet for the patent, net of accumulated amortization, at December 31, 2012
Maintaining optimal level of stock problem : Maintaining Optimal Level of Stock Problem

Reviews

Write a Review

 

JAVA Programming Questions & Answers

  Ood methodology

Your local police department wants to design new software to keep track of people, property, and criminal activity. List at least three classes you think should be in the design. For each class, identify some data members and methods.

  Define a method for linkedbag

Add a constructor to the class LinkedBag that creates a bag from a given array of entries - define a method for LinkedBag that removes a random entry from the bag.

  Declare a string variable named empty

Declare a string variable named empty, and initialize it to the empty string.

  Write a program that takes as input student scores

Write a program that takes as input student scores from a file and outputs the average for each student to a file.

  Prepare an overloaded constructor

Prepare an overloaded constructor that provides values for each field. Also provide get methods for each field. Save the file as Patient.java.

  I had to call a webservice

I had to call a webservice (1st line of code) and then from there created a loop but keep getting an error every time on the .getBusiness - I don't know what I should be using there instead of getBusiness.

  What is the average response time for this system?

A web server receives a request every 50ms and processes web requests every 8 ms. Using queuing theory, 1. What is the average response time for this system?

  Implement a thread for each creature representing a task

Implement a threads and a GUI interface using advanced Java Swing classes.

  Explain the relationship between a class and an object

Classes and objects are the fundamental concepts of object-oriented programming language. What are classes and objects? Explain the relationship between a class and an object

  Determine values of the side of triangle

Enter 3 integers and determine if these 3 values make up the sides of a triangle. If any side is

  Aims1 to understand actual communication with an smtp

aims1. to understand actual communication with an smtp server can be achieved using tcp sockets.2. to understand the

  Write program that uses top five countries national wealth

Write a program that uses the top five countries' National Wealth to calculate the average of those five countries.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd