Please Complete the following4 Exercises which account for Chapter 1 Activities
ID: 3844058 • Letter: P
Question
Please Complete the following4 Exercises which account for Chapter 1 Activities (5 Points). Turn a .zip of the 4 java files and a Word document with the outputs (Only 1 sample each needed). *1.3 (Display a pattern) Write a program that displays the following pattern: Sample Run for Exercise01 03 command javac Exercise 03.java Compiled successful command java Exercise 1.03 AA AA V V J J command 1.4 (Print a table) Write a program that displays the following table: Sample Run for Exerciseo1 04 command javac Exercise 04.java Compiled successful command java Exercisee1 04 a 2 a 3 27 16 command 1.10 (Average speed in miles) Assume a runner runs 14 kilometers in 45 minutes and 30 seconds. Write a program that displays the average speed in miles per hour. (Note that 1 mile is 1.6 kilometers.) "1.11 (Population projection) The U.S. Census Bureau projects population based on the following assumptions: One birth every 7 seconds One death every 13 seconds One new immigrant every 45 secondsExplanation / Answer
//Exercise01_04
public class Exercise01_04 {
/**
* @param args
*/
public static void main(String[] args) {
// to print the table
System.out.println("a a^2 a^3");
for (int i = 1; i <= 4; i++) {
// calculate index, square and cube and print
System.out.println(i + " " + (i * i) + " " + (i * i * i));
}
}
}
OUTPUT:
a a^2 a^3
1 1 1
2 4 8
3 9 27
4 16 64
import java.util.Scanner;
//Exercise02_03
public class Exercise02_03 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scanner = null;
try {
// prepare scanner reading data from keyboard
scanner = new Scanner(System.in);
// prompt to enter the value in feet
System.out.print("Enter a value for feet:");
double feet = scanner.nextDouble();
// convert feet to meters
double meters = feet * 0.305;
// print the result
System.out.println(feet + " feet is " + meters + " meters");
} catch (Exception e) {
// TODO: handle exception
}
}
}
OUTPUT:
Enter a value for feet:16.5
16.5 feet is 5.0325 meters
import java.util.Scanner;
//Exercise02_04
public class Exercise02_04 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scanner = null;
try {
// prepare scanner reading data from keyboard
scanner = new Scanner(System.in);
// prompt to enter the number in pounds
System.out.print("Enter the number in pounds:");
double pounds = scanner.nextDouble();
// convert pounds to kilogram
double kilogram = pounds * 0.454;
// print the result
System.out
.println(pounds + " pounds is " + kilogram + " kilograms");
} catch (Exception e) {
// TODO: handle exception
}
}
}
OUTPUT:
Enter the number in pounds:55.5
55.5 pounds is 25.197 kilograms
import java.util.Scanner;
//Exercise02_06
public class Exercise02_06 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scanner = null;
try {
// prepare scanner reading data from keyboard
scanner = new Scanner(System.in);
// prompt to enter the number between 0 and 100
System.out.print("Enter a integer between 0 and 100:");
int n = scanner.nextInt();
int sum = 0, r, val = n;
while (n != 0) {
// get the remainder
r = n % 10;
// add to sum
sum += r;
// division for doing remaining
n = n / 10;
}
// print the result
System.out
.println("the sum of all digits in " + val + " is " + sum);
} catch (Exception e) {
// TODO: handle exception
}
}
}
OUTPUT:
Enter a integer between 0 and 100:435
the sum of all digits in 435 is 12
import java.util.Scanner;
//Exercise02_09
public class Exercise02_09 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scanner = null;
try {
// prepare scanner reading data from keyboard
scanner = new Scanner(System.in);
double v0, v1, t, a;
// prompt to enter the input
System.out.print("Enter v0, v1 and t:");
v0 = scanner.nextDouble();
v1 = scanner.nextDouble();
t = scanner.nextDouble();
a = (Math.max(v0, v1) - Math.min(v0, v1)) / t;
// print the result
System.out.println("the average accelaration is " + a);
} catch (Exception e) {
// TODO: handle exception
}
}
}
OUTPUT:
Enter v0, v1 and t:5.5 50.9 4.5
the average accelaration is 10.088888888888889
Note: I done with some of the questions, please post the remaining questions as different post