# CS 570: Programming Foundations Homework Assignment #5 Solved

25.00 \$

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . ` zip` solution files instantly, after Payment

## Description

5/5 - (1 vote)

Â Note: This and all assignments given in this course can be and must be solved using only the materials that have been discussed in class.Â  Do not look for alternative methods that have not been covered as part of this course.

Â

Program (60 points):

We are going to write a program that allows the user to calculate his/her weight on any given planet in the solar system.Â  Here is the data you will need:

 Planet Planet Surface Gravity Mercury 0.39 Venus 0.91 Earth 1.00 Mars 0.38 Jupiter 2.87 Saturn 1.32 Uranus 0.93 Neptune 1.23 Pluto 0.03

Note: yes, Pluto is a planet (a dwarf planet):

For example, if your weight on Earth is 120 pounds, then your weight in Venus is 120 * 0.91 = 109.2 pounds; and your weight in Pluto is 3.6 pounds.

# Program Details

For this assignment you will need to use: arrays, loops, selection statements, and write some methods.

You will store the names of the planets in an array of Strings, and the planetsâ€™ surface gravity factors in an array of doubles.

The program will have a menu with the following options:

• Enter 1 to find your weight on a given planet.
• Enter 2 to see your weight on all planets.
• Enter 3 to display all planets and gravity factors.
• Enter 4 to show this menu again.
• Enter any other number to exit the program.

The user will enter his/her choice and the program will complete the appropriate tasks.

For option 1: the program must ask the user to enter his/her weight in pounds and the code for the planet he/she wants.Â  You can use the index of the elements in the array as the code for the planets (so for example 0 corresponds to Mercury, 1 to Venus, and so on). The inputs provided by the user must be validated: do not allow weights less than 1, or invalid codes for planets. Once you have valid data, invoke a method that will calculate and return the weight of the user in the desired planet.

For option 2: the program must ask the user to enter his/her weight in pounds (do not allow weights less than 1). Once you have a valid weight invoke a method that will display a table with all the planetsâ€™ names and the corresponding weights on the planets.

For option 3: invoke a method that will display the names of the planets and their surface gravity factors.

Here is a sample run of a typical solution to this problem:

Note:Â  Please make sure to submit well-written programs for these programming tasks. Good identifier names, useful comments, indentation, and spacing will be some of the criteria that will be used when grading this assignment.

Sorting Algorithms (40 points):

For the following list of numbers:

9 0 11 10 5 8 6 7Â

1. Show the sequence of changes the Bubble Sort algorithm makes to sort the list of numbers.

1. Show the sequence of changes the Selection Sort algorithm makes to sort the list of numbers.

1. Show the sequence of changes the Insertion Sort algorithm makes to sort the list of numbers.

1. Show the sequence of changes the Merge Sort algorithm makes to sort the list of numbers.

For examples, please refer to the slides in week 5 and examples on your textbook (Chapter 10, section 4)

• Week-5.zip