Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSC 120 Programming Project #1 Objectives: To demonstrate an understanding program logic by tracing through a program. To gain experience using the Eclipse IDE. To

CSC 120 Programming Project #1

image text in transcribed

image text in transcribed

image text in transcribed

Objectives: To demonstrate an understanding program logic by tracing through a program. To gain experience using the Eclipse IDE. To debug a program so that it produces the proper output. Specifications: Understanding Program Logic: Trace through the program below (continued on the next page) to determine what it does. In a plain text file, type what is stored in each constant and variable as the program executes as well as the output produced (similar to Lab #1). Be sure to label what will appear on the screen as output. Assume the user types 750 as the input when prompted: + /** *

Title: Project #1 Trace - Winter Storm

*

Description: Winter Storm Harper hit the northeast hard leaving many people without * electricity. Most people do not have generators, so they need shelters to keep them * and their pets warm. This program used by a county will prompt the user for the number * of households without power and determine what emergency personal/services are needed. * @author Prof. Postner */ public class ProjectiTrace { public static void main(String[] args) { final int MAX_PEOPLE_PER_SHELTER = 100; final int MAX_HOUSEHOLDS_PER_ELECTRICIAN = 40; final int AVG_RESIDENTS = 4; final double PERCENT_PETS = 0.35; int numPeople; int numPets; int numShelters; int numHouseholds; int numElectricians; int numExtra; Scanner scnr = new Scanner(System.in); System.out.println("How many households in the county are without power?"); numHouseholds - scnr.nextInt(); numPeople = numHouseholds * AVG_RESIDENTS; numPets = (int) (numHouseholds * PERCENT_PETS); System.out.println("There are approximately " + numPeople + " people without power."); System.out.println("There are approximately " + numPets + " pets that need to be kept warm."); numShelters = numPeople + numpets / MAX_PEOPLE_PER_SHELTER + 1; System.out.println("The county needs to open " + numShelters + " emergency shelters for those without power."); numElectricians = numHouseholds / MAX_HOUSEHOLDS_PER_ELECTRICIAN; numExtra = numHouseholds % MAX_HOUSEHOLDS_PER_ELECTRICIAN; System.out.println(numElectricians + " electrician crews are needed to restore power to " + numExtra + " families. InThere are numHouseholds + " households that will not be taken care of today."); + } } Debugging Program Logic: Create a project called projl (all lowercase, no spaces). Within this project create a class called Project] (the project name should begin with a capital letter, everything else is lower case, no spaces). Be careful to create your project and class correctly. Use your labo handout as a reference. Remember to specify the package name as projl when you create the Project1 class. Open the Projectl file on Blackboard and copy/paste it into the class you just created, deleting the code that was there initially. This program is supposed to ask the user for a product brand and product description as a single line of input which the user types as input. It should also prompt the user to enter the product price and product weight in ounces. The program should then create output in the following format (pay attention to blank lines). Please note: This is sample output based upon the user typing in Kraft Mac & Cheese as the product brand/description, 2.1 as the product price and 10.5 as the weight in ounces. When you test the program with other inputs, the format should be similar, but the values displayed will differ. Brand: Kraft Type: Mac & Cheese There are 5 letters in the product brand There are 12 letters in the product type There are 18 letters in the full product description Brand initial: K Type initial: M Product Price: $2.1 Product Weight (in ounces): 10.5 Product Price Per Ounce: $0.2 Run the program, type in Kraft Mac & Cheese, 2.10 and 10.5 when prompted for input. Look at the output carefully. It does not match the sample above. Some of the output is incorrect, some is missing and some is incorrectly formatted. Determine what the problems are and fix them so that the program works properly. For each line you change write a comment on the line directly above the statement being changed that explains the problem with the initial code and how you changed it. Be sure to test your program with several different inputs for all the product information (brand, description, price and weight) to make sure it works properly regardless of what the user entered. Please note: Depending upon the price and weight you enter you may get a price per ounce with more than two decimal places or one that has a rounding error (ie. something like 0.1999999999989 instead of 0.2) do not worry about either of these problems. When you are done, complete the comment at the beginning of your program by filling in the title of the program (something like Project 1: Product Information), a description of what the program does (this should be 2-3 sentences that explains what your program does as if you were talking to someone who doesn't know anything about programming) and your name as the author

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

5. Discuss the key components of behavior modeling training.

Answered: 1 week ago