The pseudocode below has been written as an algorithmic solution to the following programming task but is
Question:
The pseudocode below has been written as an algorithmic solution to the following programming task but is not complete and may include some incorrect logic. the pseudocode to incorporate all aspects of the following programming task and ensure that the output is correct before writing the Java source code.
In the fire swamp located between Florin and Guilder, Rodents of Unusual Size roam. They are just one of the three dangers that travelers must overcome if they are to survive their journey through the swamp. a program that will predict the size of a population of Rodents of Unusual Size over time (years). The program should ask for the starting number of Rodents of Unusual Size, their average annual population increase (as a percentage), and the number of years they will multiply. For example, a population of Rodents of Unusual Size might begin with 400, have an average annual increase of 2 percent, and be allowed to multiply for twelve years. The program must display the predicted size of the Rodents of Unusual Size population for each year.
Do not accept a number less than 300 for the initial size of the population. Do not accept a negative number for average annual population increase (note: average annual
population increase already includes deaths due to old age, disease, predatory hunting (not likely), natural disasters, flame spurts, and encounters with Westley, etc). Do not accept a number less than 10 for the number of years the population will multiply. The Scanner class must be used for keyboard input. Arrays or arraylists are not to be used in this program. Initial pseudocode prompt 'enter the initial population of Rodents of Unusual Size' get initial population prompt 'enter annual population increase percentage' get percentage increase prompt 'enter a number of years to estimate population' get a number of years.
for each year
display year, population
population = population + population * increase/100
Note: Correct the initial pseudocode/algorithm for the problem, then write and test the Java source code
2. Rodents of Unusual Size Population.
Copy your code solution for question 2 from week 3 (Rodents of Unusual Size Population) into your project for week 4. Modify your solution to incorporate two methods,
validateInt and validateFloat. Both methods should have two parameters, the number to be validated, and the minimum value allowed. Call the appropriate method(s) to
validate the user input before performing the calculations. All other aspects of the question are unchanged from week 3. The Scanner class must be used for keyboard input.
3. a. As mentioned in the week 3 lecture Java defines a static method in the Math class named pow. Its purpose is to calculate the result of raising a number (the base) to the
power of a second number (the exponent), for example 194. The pow method can be called in a Java program by using a statement like Math.pow(base, exponent).
Java method named power that performs the same task as Math.pow. Your power method will need two integer parameters that represent the base and
the exponent. Your power method should return the result of raising the base to the exponent (ie, baseexponent). Your power method must not call the Math.pow method.
Note: your power method will only be accurate for relatively small values of the base and exponent.
Recall from basic mathematics that to calculate ab means multiplying a by itself b times, and that a0 = 1. For example:
53 = 5 * 5 * 5
194 = 19 * 19 * 19 * 19
270 = 1
50 = 1
The program fragment below obtains two positive whole numbers from the user, displaying the result of passing them to your power method and the Math.pow method.
Secondly, the program displays a SUCCESS message if the result of your power method is equivalent to the result of the Math.pow method (Note: your power method will
only be accurate for relatively small values of the base and exponent), or a FAILURE message otherwise. The Scanner class must be used for keyboard input.
static Scanner kb = new Scanner(System.in);
public static void main(String[] args) {
int base;
int exponent;
System.out.print("Enter a positive base: ");
base = kb.nextInt();
System.out.print("Enter a positive exponent: ");
exponent = kb.nextInt();
System.out.println("My power method result: " + base + " raised to the power of " + exponent + " = " + call_your_power_method_here);
System.out.println("Math.pow method result: " + base + " raised to the power of " + exponent + " = " + Math.pow(base, exponent));
if (call_your_power_method_here == Math.pow(base, exponent)) {
System.out.println("SUCCESS - it looks like you wrote the power method correctly.");
} else {
System.out.println("Try again with smaller values of the base and exponent or something appears to be wrong with your power method.");
}
When writing the method ask yourself the following questions to help determine how the power method will be called/used:
§ What is the purpose of the method (all methods should perform only one task)? Remember that 'one task' does not necessarily mean 'one executable statement'.
§ What are the main outputs of the power method - are there any?
§ What are the inputs to the power method - are there any?
§ What are the processing steps that the method will need to perform?
b. Write another method that will validate an integer number to ensure that it is not negative. Incorporate this method into your program to validate the base and exponent.
Test your code
4. Sydney Temperatures.
Java program that allows a user to enter a series of daily maximum temperatures (in degrees Celsius (°C)) recorded in Sydney over a period of time. The user should enter a
sentinel value (-999) to signal the end of the temperature entry. Temperatures entered by the user that are below -10°C or 50°C and above should be ignored.
Each temperature entered by the user should be categorized by the program into the following ranges:
• Freezing (below 0.0°C)
• Cold (from 0.0°C to below 10.0°C)
• Mild (from 10.0°C to below 20.0°C)
• Warm (from 20.0°C to below 30.0°C)
• Hot (from 30.0°C to below 40.0°C)
• Extreme (40.0°C and above)
After temperature entry is completed, the program should display the number of days in each range and the average temperature in each range.
The program must include appropriate methods using appropriate parameter passing. The Scanner class must be used for keyboard input. Arrays or array lists are not to be used in
this program.
Example execution of the program may be as follows:
Welcome to the Sydney Daily Maximum Temperature Analyser!
Enter the daily maximum temperatures for Sydney. Enter -999 to finish.
Enter temperature for day 1: 15
Enter temperature for day 2: 25.4
Enter temperature for day 3: 5.7
Enter temperature for day 4: 30
Enter temperature for day 5: 42
Enter temperature for day 6: 27
Enter temperature for day 7: -999
===== Temperature Analysis =====
Freezing: 0 day(s), average temperature: N/A
Cold: 1 day(s), average temperature: 5.7°C
Mild: 1 day(s), average temperature: 15.0°C
Warm: 2 day(s), average temperature: 26.2°C
Hot: 1 day(s), average temperature: 30.0°C
Extreme: 1 day(s), average temperature: 42.0°C
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill