Docsity

Homework Assignment 3 on Introduction-Computer Science | CS 110, Assignments of Computer Science

Toggle sidebar
bg1
CS 110 Homework assignment 3
Page 171 #6 (5 points)
a). G
b). h
c). 27
d). 6
e). 23
Page 451#6 (8 points)
a). 4 parameters, int type
b) 2 parameters, double type
c). 4 parameters, char type
d). 4 actual parameters are needed, int, char, double, and int
e). System.out.println(test(5,’z’,7.3,5));
f). System.out.pirntln(two(17.5,18.3));
g). assume x=1,y=3,ch=’b’,d=6.5
System.out.println(1,3,’b’,6.5);
Page 459#6 (7 points)
import java.util.Scanner;
import java;lang.Math;
public class Hmwk3
{
static Scanner sc = new Scanner(System.in);
public static void main(String [] agrs)
{
double pop, estPop, birthRate, deathRate, growthRate;
int numYears;
System.out.print(“Please enter the starting population: “);
pop = sc.nextDouble();
System.out.print(“Please enter the Birth Rate: “);
birthRate = sc.nextDouble();
System.out.print(“Please enter the death rate: “);
deathRate =sc.nextDouble();
System.out.print(“Please enter the number of years: “);
numYears = sc.nextInt();
if (pop <=2 || birthRate < 0 || deathRate <0)
System.out.println (“Illegal values, birth rate and death rate must
be > 0 and population must be >2”);
else
pf2

Partial preview of the text

Download Homework Assignment 3 on Introduction-Computer Science | CS 110 and more Assignments Computer Science in PDF only on Docsity!

CS 110 Homework assignment 3

Page 171 #6 (5 points) a). G b). h c). 27 d). 6 e). 23

Page 451#6 (8 points) a). 4 parameters, int type b) 2 parameters, double type c). 4 parameters, char type d). 4 actual parameters are needed, int, char, double, and int e). System.out.println(test(5,’z’,7.3,5)); f). System.out.pirntln(two(17.5,18.3)); g). assume x=1,y=3,ch=’b’,d=6. System.out.println(1,3,’b’,6.5);

Page 459#6 (7 points)

import java.util.Scanner; import java;lang.Math;

public class Hmwk { static Scanner sc = new Scanner(System.in);

public static void main(String [] agrs) { double pop, estPop, birthRate, deathRate, growthRate; int numYears;

System.out.print(“Please enter the starting population: “); pop = sc.nextDouble(); System.out.print(“Please enter the Birth Rate: “); birthRate = sc.nextDouble(); System.out.print(“Please enter the death rate: “); deathRate =sc.nextDouble(); System.out.print(“Please enter the number of years: “); numYears = sc.nextInt();

if (pop <=2 || birthRate < 0 || deathRate <0) System.out.println (“Illegal values, birth rate and death rate must be > 0 and population must be >2”); else

growthRate = growRate(birthRate,deathRate); estPop= estimatedPopulation (growthRate, pop, numYears); System.out.println(“the growth rate is” + growthRate); System.out.println(“the estimated population after “ + numYears + “years is: “ + Math.round(estpop); }

}

public static double growRate (double br, double dr) { double gr; gr = br-dr; return gr; }

public static double estimatedPopulation (double gr, double pop, int years) { double ep; ep = p * Math.pow(1+gr/100,years); return ep; } }