Skip to content

Instantly share code, notes, and snippets.

@elizmcdnld
elizmcdnld / ex4point2.java
Created February 26, 2017 00:51
Chapter 4 - Exercise 4.2
import java.util.Scanner;
public class ex4point2 {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
System.out.println("Please enter the latitude and longitude (in degrees) of the first point.");
double x1 = userInput.nextDouble();
double y1 = userInput.nextDouble();
@elizmcdnld
elizmcdnld / ex2point23.java
Created February 25, 2017 10:05
Ch. 2 - Exercise 2.23
// Write a program that prompts the user to enter the distance to drive, the fuel
// efficiency of the car in miles per gallon, and the price per gallon, and displays
// the cost of the trip.
import java.util.Scanner;
public class ex2point23 {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
@elizmcdnld
elizmcdnld / ex2point20
Created February 25, 2017 10:02
Ch. 2 - Exercise 2.20
// If you know the balance and the annual percentage interest rate, you can compute
// the interest on the next monthly payment using the following formula:
// interest=balance*(annualInterestRate/1200)
// Write a program that reads the balance and the annual percentage interest rate
// and displays the interest for the next month.
import java.util.Scanner;
public class ex2point20 {
public static void main(String[] args) {
@elizmcdnld
elizmcdnld / ex2point5.java
Created February 25, 2017 10:01
Ch. 2 - Exercise 2.15
//Write a program that reads the subtotal and the gratuity rate, then computes the
//gratuity and total. For example, if the user enters 10 for subtotal and 15% for
//gratuity rate, the program displays $1.5as gratuity and $11.5 as total.
import java.util.Scanner;
public class ex2point5 {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
@elizmcdnld
elizmcdnld / ex2point4.java
Last active February 25, 2017 10:00
Ch. 2 - Exercise 2.4
// (Convert pounds into kilograms) Write a program that converts pounds into kilograms.
// The program prompts the user to enter a number in pounds, converts it to kilograms,
// and displays the result. One pound is 0.454 kilograms.
import java.util.Scanner;
public class ex2point4 {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
@elizmcdnld
elizmcdnld / ex1point13.java
Created February 25, 2017 09:51
Chapter 1 - Exercise 1.13
// Solve the following: 3.4x + 50.2y = 44.5
// 2.1x + 0.55y = 5.9
public class ex1point13 {
public static void main(String[] args) {
// Below numbers based on Cramer's formula as solved in notebook
double a = 3.4;
double b = 50.2;
double c = 2.1;
@elizmcdnld
elizmcdnld / ex1point11.java
Created February 25, 2017 09:50
Chapter 1 - Exercise 1.11
public class ex1point11 {
public static void main(String[] args) {
int initialPopulation = 312032486;
int yearlySeconds = 60 * 60 * 24 * 365;
int yearlyBirths = yearlySeconds / 7;
int yearlyDeaths = yearlySeconds / 13;
int yearlyImmigrants = yearlySeconds / 45;
int yearlyPopChange = yearlyBirths + yearlyImmigrants - yearlyDeaths;
int popAfterOneYear = initialPopulation + yearlyPopChange;
@elizmcdnld
elizmcdnld / ex1point10.java
Created February 25, 2017 09:50
Chapter 1 - Exercise 1.10
public class ex1point10 {
public static void main(String[] args) {
System.out.println("Assume a runner runs 14 kilometers in 45 minutes and 30 seconds. What is the average speed in miles per hour?");
System.out.println("1 mile = 1.6 kilometers. Therefore, 14 kilometers equals 8.699 miles.");
System.out.println("60 minutes are in an hour. Therefore, 45.5 minutes is 0.7583 hours.");
System.out.println("We can find the average by dividing 8.699 / 0.7583");
System.out.println(8.699 / 0.7583);
System.out.println("The runner progresses approximately 11.5 miles per hour.");
}
}
@elizmcdnld
elizmcdnld / ex1point8.java
Created February 25, 2017 09:48
Ch. 1 - Exercise 1.8
// Write a program that displays the area and perimeter of a circle that has a radius
//of 5.5
public class ex1point8 {
public static void main(String[] args) {
double radius;
double area;
radius = 20;
@elizmcdnld
elizmcdnld / ex1point7.java
Created February 25, 2017 09:47
Ch.1 - Ex 1.7
public class ex1point7 {
public static void main(String[] args){
System.out.println(4 * (1.0 - (1.0/3) + (1.0/5) - (1.0/7) + (1.0/9) - (1.0/11)));
System.out.println(4 * (1.0 - (1.0/3) + (1.0/5) - (1.0/7) + (1.0/9) - (1/11) + (1.0/13)));
}
}