
<p>CS1043 LAB-5 Emissions Limits </p><p>Write a Java program that interacts with a user by printing out a list of pollutants and requests input from the user as follows:</p><p>1. Carbon monoxide 2. Hydrocarbons 3. Nitrogen oxides 4. Non-methane hydrocarbons</p><p>Enter pollutant number => Enter number of grams emitted per mile => Enter odometer reading =></p><p>Use this table of emissions limits to determine the appropriate output message.</p><p>Maximum allowed for Maximum allowed for the first 50,000 miles the next 50,000 miles 0 milage 50000 50000 milage 100000 ______Carbon Monoxide 3.4 grams/mile 4.2 grams/mile Hydrocarbons 0.31 grams/mile 0.39 grams/mile Nitrogen Oxides 0.4 grams/mile 0.5 grams/mile Nonmethane hydrocarbons .25 grams/mile .31 grams/mile</p><p>To receive full credit for this project, you must include, 1. one switch statement 2. nested if-control structure 3. Write a static method with the following header line and arguments:</p><p> public static boolean mileageGramsLogic( int actualMileage, int firstMileageLimit, int secondMileageLimit, double actualGrams, double firstGramLimit, double secondGramLimit )</p><p>(See the next page for more instructions.) Run your program for these three different cases:</p><p>Enter pollutant number => 2 Enter number of grams emitted per mile => 0.35 Enter odometer reading => 40112</p><p>Enter pollutant number => 3 Enter number of grams emitted per mile => 0.61 Enter odometer reading => 101000</p><p>Enter pollutant number => 4 Enter number of grams emitted per mile => 0.27 Enter odometer reading => 60200</p><p>The mileagGrams Logic return a Boolean: either the emission amount is or is not within the permitted limit. Print messages like this:</p><p> Emissions exceed the permitted level. Emissions are within the permitted level.</p><p>Note there is no emission limit for mileage beyond 100000 miles. public class EmissionsLab5 { public static void main( String [] args ) { // Declare ALL your variables here: int pollutantNumber; . . . int firstGramLimit; . . . // display the 4 pollutant choices: CO, HC, NO, other System.out.println( " … " );</p><p>// Prompt for the three inputs: pollutant #, grams, mileage System.out.print( " … " );</p><p>// Create a switch switch pollutantNumber; { case 1: firstGramLimit = 3.4; case 2: </p><p> case 3: }</p><p> boolean result = mileageGramsLogic( … );</p><p> if ( result ) // display message else // display other message</p><p>}</p><p> public static boolean mileageGramsLogic( … ) { // use a nested-if control structure and separate the // logic for mileage and pollutant grams.</p><p> return false ; // fix this.</p><p>}</p><p>}</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages3 Page
-
File Size-