You are on page 1of 61

Big Java Late Objects 1st Edition

Horstmann Solutions Manual


Visit to download the full and correct content document: https://testbankdeal.com/dow
nload/big-java-late-objects-1st-edition-horstmann-solutions-manual/
Chapter 8 Programming Exercise Solutions

P8.1

public void undo()


{
int undo = 0;

if (undo <= value)


{
undo++;
value--;
}
}

P8.2

/**
This class models a tally counter.
*/
public class Counter
{
private int value;
private int max;

public void setLimit(int maximum)


{
max = maximum;
}

/**
Gets the current value of this counter.
@return the current value
*/
public int getValue()
{
return value;
}

/**
Advances the value of this counter by 1.
*/
public void count()
{
value = value + 1;
if (value >= max)
{
System.out.println("Limit exceeded");
reset();
}
}

/**
Resets the value of this counter to 0.

© John Wiley & Sons, Inc. All rights reserved. 1


*/
public void reset()
{
value = 0;
}
}

P8.3

import java.util.Scanner;
/**
A class that keeps track of a dynamic menu.
*/
public class Menu
{
private String menuItems;
private int optionCount;
private Scanner in;

/**
Constructs a menu with no options.
*/
public Menu()
{
menuItems = "";
optionCount = 0;
in = new Scanner(System.in);
}

/**
Adds an option to the end of this menu.
@param option the option to add
*/
public void addOption(String option)
{
optionCount++;
menuItems = menuItems + optionCount + ") " + option + "\n";
}

/**
Displays the menu, with options numbered starting with 1,
and prompts the user for input. Repeats until a valid input
is supplied.
@return the number that the user supplied
*/
public int getInput()
{
int input;
do
{
System.out.print(menuItems);
input = in.nextInt();
}
while (input < 1 || input > optionCount);
return input;

© John Wiley & Sons, Inc. All rights reserved. 2


}
}

P8.4

/**
A class to keep track of, print, and compare addresses with and
without apartment numbers.
*/
public class Address
{
private String houseNumber;
private String apartmentNumber;
private String street;
private String city;
private String state;
private String postalCode;

/**
Constructs an address with everything but an apartment number.
@param houseNumber the house number as a string
@param street the street as a string
@param city the city as a string
@param state the state as a string
@param postalCode the postal code as a string
*/
public Address(String houseNumber, String street, String city, String state,
String postalCode)
{
this.houseNumber = houseNumber;
this.apartmentNumber = "";
this.street = street;
this.city = city;
this.state = state;
this.postalCode = postalCode;
}

/**
Constructs an address with an apartment number
@param houseNumber the house number as a string
@param apartmentNumber the apartment number as a string
@param street the street as a string
@param city the city as a string
@param state the state as a string
@param postalCode the postal code as a string
*/
public Address(String houseNumber, String apartmentNumber, String street,
String city, String state, String postalCode)
{
this.houseNumber = houseNumber;
this.apartmentNumber = apartmentNumber;
this.street = street;
this.city = city;
this.state = state;
this.postalCode = postalCode;

© John Wiley & Sons, Inc. All rights reserved. 3


}

public void print()


{
System.out.println(houseNumber + " " + street + " " + apartmentNumber);
System.out.println(city + ", " + state + " " + postalCode);
}

/**
Compares two addresses by postal code
@param other the other address
@return true if the distinguished argument's postal code is less
than other 's postal code
*/
public boolean comesBefore(Address other)
{
return postalCode.compareTo(other.postalCode) < 0;
}
}

P8.5

/**
Class to get surface area and volume of a soda can.
*/
public class SodaCan
{
private double height;
private double radius;

/**
Initializes a can with given height and radius.
@param height the height
@param radius the radius
*/
public SodaCan(double height, double radius)
{
this.height = height;
this.radius = radius;
}

/**
Calculates the surface area of the soda can.
@return the surface area of the soda can
*/
public double getSurfaceArea()
{
return 2 * Math.PI * radius * (radius + height);
}

/**
Calculates the volume of the soda can.
@return the volume of the soda can
*/
public double getVolume()

© John Wiley & Sons, Inc. All rights reserved. 4


{
return Math.PI * radius * radius * height;
}
}

P8.6

/**
A class suitable for the simulating a car driving.
*/
public class Car
{
private double fuelEfficiency;
private double gasLevel;

/**
Initializes a car with a given fuel efficiency
@param fuelEfficiency the default fuel efficiency
*/
public Car(double fuelEfficiency)
{
this.fuelEfficiency = fuelEfficiency;
gasLevel = 0;
}

/**
Puts gas in the tank.
@param gas amount of gas to add
*/
public void addGas(double gas)
{
this.gasLevel = gasLevel + gas;
}

/**
Simulates driving the car and thus reducing the gas in the tank
@param distance miles driven
*/
public void drive(double distance)
{
gasLevel -= distance / fuelEfficiency;
}

/**
Returns the current gas level.
@return current gas level
*/
public double getGasLevel()
{
return gasLevel;
}
}

© John Wiley & Sons, Inc. All rights reserved. 5


P8.7

/**
A class to represent the quiz scores of a student.
*/
public class Student
{
private String name;
private int totalQuizScore;
private int numberOfQuizzes;

/**
Initializes a new student with a name and a 0 total quiz score.
*/
public Student(String name)
{
this.name = name;
totalQuizscore = 0;
}

/**
Gets the student's name.
@return the student's name
*/
public String getName()
{
return name;
}

/**
Adds one quiz to the student's record.
@param score the score of the quiz
*/
public void addQuiz(int score)
{
totalQuizScore += score;
numberOfQuizzes++;
}

/**
Returns the student's total score.
@return the student's total score
*/
public int getTotalScore()
{
return totalQuizScore;
}

/**
Calculates and returns the student's average quiz score
@return the student's average quiz score
*/
public double getAverageScore()
{
if (numberOfQuizzes > 0)
{

© John Wiley & Sons, Inc. All rights reserved. 6


return totalQuizScore / (double) (numberOfQuizzes);
}
}
}

P8.8

As this solution requires two classes, Grade is listed first, then Student.

/**
A class to construct a grade from a string.
*/
public class Grade
{
private String grade;

/**
Constructs a grade from a string
@param gradeAsString a valid letter grade such as A, A-, B+, etc.
*/
public Grade(String gradeAsString)
{
grade = gradeAsString;
}

/**
Calculates the numeric value of the grade.
@return the numeric value of the grade
*/
public double getNumericValue()
{
double numericGrade;
if (grade.charAt(0) == 'A')
{
numericGrade = 4.0;
}
else if (grade.charAt(0) == 'B')
{
numericGrade = 3.0;
}
else if (grade.charAt(0) == 'C')
{
numericGrade = 2.0;
}
else if (grade.charAt(0) == 'D')
{
numericGrade = 1.0;
}
else
{
numericGrade = 0.0;
}

if (grade.length() > 1)

© John Wiley & Sons, Inc. All rights reserved. 7


{
if (grade.charAt(1) == '+')
{
numericGrade += .3;
}
if (grade.charAt(1) == '-')
{
numericGrade -= .3;
}
}
return numericGrade;
}
}

/**
A class to represent a student with grades.
*/
public class Student
{
private String name;
private double totalGrade;
private int numberOfGrades;

/**
Initializes a new student with a name and a 0 total grade.
*/
public Student(String name)
{
this.name = name;
totalGrade = 0;
numberOfGrades = 0;
}

/**
Gets the student's name.
@return the student's name
*/
public String getName()
{
return name;
}

/**
Adds one grade to the student's record.
@param grade the student's grade
*/
public void addGrade(Grade grade)
{
totalGrade += grade.getNumericValue();
numberOfGrades++;
}

/**
Returns the student's GPA.
@return the student's GPA
*/
public double getGPA()

© John Wiley & Sons, Inc. All rights reserved. 8


{
if (numberOfGrades > 0)
{
return totalGrade / numberOfGrades;
}
}
}

P8.9

/**
A class to simulate a combination lock.
*/
public class ComboLock
{
private int secret1;
private int secret2;
private int secret3;

// 0: nothing entered, 1: secret1 done, 2: secret2 done,


// 3: secret3 done and unlocked
private int lockState;

private int currentNumber;


private boolean validSoFar;

/**
Initializes the combination of the lock.
@param secret1 first number to turn right to
@param secret2 second number to turn left to
@param secret3 third number to turn right to
*/
public ComboLock(int secret1, int secret2, int secret3)
{
this.secret1 = secret1;
this.secret2 = secret2;
this.secret3 = secret3;
lockState = 0;
currentNumber = 0;
validSoFar = true;
}

/**
Resets the state of the lock so that it can be opened again.
*/
public void reset()
{
lockState = 0;
currentNumber = 0;
validSoFar = true;
}

/**
Turns lock left given number of ticks.
@param ticks number of ticks to turn left

© John Wiley & Sons, Inc. All rights reserved. 9


*/
public void turnLeft(int ticks)
{
currentNumber = (currentNumber + ticks) % 40;
// State 1 is the only valid state in which to turn the lock
if (lockState == 1)
{
if (currentNumber == secret2)
{
lockState = 2;
}
}
else
{
validSoFar = false;
}
}

/**
Turns lock right given number of ticks
@param ticks number of ticks to turn right
*/
public void turnRight(int ticks)
{
currentNumber = (currentNumber - ticks + 40) % 40;
// States 0 and 2 are the only valid states in which to turn the lock
if (lockState == 0)
{
if (currentNumber == secret1)
{
lockState = 1;
}
}
else if (lockState == 2)
{
if (currentNumber == secret3)
{
lockState = 3;
}
}
else
{
validSoFar = false;
}
}

/**
Returns true if the lock can be opened now
@return true if lock is in open state
*/
public boolean open()
{
return lockState == 3 && validSoFar;
}
}

© John Wiley & Sons, Inc. All rights reserved. 10


P8.10

/**
A voting machine that can be used for a simple election.
*/
public class VotingMachine
{
private int democratVotes;
private int republicanVotes;

/**
Initializes a blank voting machine.
*/
public VotingMachine()
{
democratVotes = 0;
republicanVotes = 0;
}

/**
Adds one vote for a Democrat.
*/
public void voteDemocrat()
{
democratVotes++;
}

/**
Adds one vote for a Republican.
*/
public void voteRepublican()
{
republicanVotes++;
}

/**
Reports the Democrat tally.
@return the Democrat tally
*/
public int democratTally()
{
return democratVotes;
}

/**
Reports the Republican tally.
@return the Republican tally
*/
public int republicanTally()
{
return republicanVotes;
}

/**
Erase all votes in machine.

© John Wiley & Sons, Inc. All rights reserved. 11


*/
public void clear()
{
democratVotes = 0;
republicanVotes = 0;
}
}

P8.11

This solution has two classes, Letter and TestLetter:

/**
A class that makes a letter.
*/
public class Letter
{
private String from;
private String to;
private String messageText;

/**
Takes the sender and recipient and initializes the letter.
@param recipient the recipient
@param sender the sender
*/
public Letter(String from, String to)
{
this.to = to;
this.from = from;
messageText = "";
}

/**
Appends a line of text to the message body.
@param line the line to append
*/
public void addLine(String line)
{
messageText = messageText + "\n" + line;
}

/**
Makes the message into one long string.
*/
public String getText()
{
return "Dear " + to + ":\n" + messageText + "\n\nSincerely,\n\n" + from;
}

/**
Prints the message text.
*/
public void print()

© John Wiley & Sons, Inc. All rights reserved. 12


{
System.out.print(getText());
}
}

public class TestLetter


{
public static void main(String[] args)
{
Letter dearJohn = new Letter("Mary", "John");
dearJohn.addLine("I am sorry we must part.");
dearJohn.addLine("I wish you all the best.");
dearJohn.print();
}

P8.12

This solution consists of two classes, Bug and TestBug:

/**
A class that simulates a bug moving.
*/
public class Bug
{
private int position;
private boolean movingRight;

/**
Initializes the bug given a position.
@param initialPosition the initial position
*/
public Bug(int initialPosition)
{
position = initialPosition;
movingRight = true;
}

/**
Changes the direction the bug is moving.
*/
public void turn()
{
movingRight = !movingRight;
}

/**
Moves the bug one unit in the current direction.
*/
public void move()
{
if (movingRight)

© John Wiley & Sons, Inc. All rights reserved. 13


{
position++;
}
else
{
position--;
}
}

/**
Reports the current position of the bug.
@return the current position
*/
public int getPosition()
{
return position;
}
}

/**
A class to test the bug class.
*/
public class TestBug
{
public static void main(String[] args)
{
Bug myBug = new Bug(10);
myBug.move();
myBug.move();
myBug.turn();
myBug.move();
myBug.turn();
myBug.move();
myBug.turn();
myBug.move();
myBug.move();
System.out.println("Expected position 10; Current position "
+ myBug.getPosition());

}
}

P8.13

This solution has two classes, Moth and TestMoth:

/**
A class that simulates a moth flying.
*/
public class Moth
{
private double position;

© John Wiley & Sons, Inc. All rights reserved. 14


/**
Initializes the moth given a position.
@param initialPosition the initial position
*/
public Moth(double initialPosition)
{
position = initialPosition;
}

/**
Moves the moth halfway to the lightPosition.
*/
public void moveToLight(double lightPosition)
{
position -= (position - lightPosition) / 2;
}

/**
Reports the current position of the moth.
@return the current position
*/
public double getPosition()
{
return position;
}
}

/**
A class to test the moth class.
*/
public class TestMoth
{
public static void main(String[] args)
{
Moth myMoth = new Moth(10);
myMoth.moveToLight(20);
System.out.println("Expected position 15; Current position "
+ myMoth.getPosition());
myMoth.moveToLight(0);
System.out.println("Expected position 7.5; Current position "
+ myMoth.getPosition());
myMoth.moveToLight(0);
System.out.println("Expected position 3.75; Current position "
+ myMoth.getPosition());
myMoth.moveToLight(0);
System.out.println("Expected position 1.875: Current position "
+ myMoth.getPosition());
}
}

P8.14

/**
A class that can calculate surface area and volume of spheres,

© John Wiley & Sons, Inc. All rights reserved. 15


cylinders,and cones.
*/
public class Geometry
{
/**
Calculates the volume of a sphere.
@param r the radius of the sphere
@return the volume of the sphere
*/
public static double sphereVolume(double r)
{
return 4.0 / 3.0 * Math.PI * Math.pow(r, 3);
}

/**
Calculates the surface area of a sphere.
@param r the radius of the sphere
@return the surface area of the sphere
*/
public static double sphereSurface(double r)
{
return 4.0 * Math.PI * r * r;
}

/**
Calculates the volume of a cylinder.
@param r the radius of the cylinder
@param h the height of the cylinder
@return the volume of the cylinder
*/
public static double cylinderVolume(double r, double h)
{
return Math.PI * r * r * h;
}

/**
Calculates the surface area of a cylinder.
@param r the radius of the sphere
@return the surface area of the cylinder
*/
public static double cylinderSurface(double r, double h)
{
return 2 * Math.PI * r * (r + h);
}

/**
Calculates the volume of a cone.
@param r the radius of the base of the cone
@param h the height of the cone
@return the volume of the cone
*/
public static double coneVolume(double r, double h)
{
return 1.0 / 3.0 * Math.PI * r * r * h;
}

/**

© John Wiley & Sons, Inc. All rights reserved. 16


Calculates the surface area of a cone.
@param r the radius of the base of the cone
@param h the height of the cone
@return the surface area of the cone
*/
public static double coneSurface(double r, double h)
{
return Math.PI * r * r + Math.PI * r * Math.sqrt(r * r + h * h);
}
}

import java.util.Scanner;

public class GeometryTest


{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter radius: ");
double radius = in.nextDouble();
System.out.println("Enter height: ");
double height = in.nextDouble();

System.out.println("Sphere volume: " +


Geometry.sphereVolume(radius));
System.out.println("Sphere surface: " +
Geometry.sphereSurface(radius));
System.out.println("Cylinder volume: "
+ Geometry.cylinderVolume(radius, height));
System.out.println("Cylinder surface: "
+ Geometry.cylinderSurface(radius, height));
System.out.println("Cone volume: " + Geometry.coneVolume(radius,
height));
System.out.println("Cone surface: "
+ Geometry.coneSurface(radius, height));
}
}

P8.15

P8.15 is more object-oriented than P8.14.

/**
A class that represents a cone and can calculate its volume and surface area.
*/
public class Cone
{
private double radius;
private double height;

/**
Creates a cone of given radius and height.
@param radius the radius

© John Wiley & Sons, Inc. All rights reserved. 17


@param height the height
*/
public Cone(double radius, double height)
{
this.radius = radius;
this.height = height;
}

/**
Calculates the volume of the cone.
@return the volume of the cone
*/
public double getVolume()
{
return 1.0 / 3.0 * Math.PI * radius * radius * height;
}

/**
Calculates the surface area of the cone.
@return the surface area of the cone
*/
public double getSurface()
{
return Math.PI * radius * radius + Math.PI * radius
* Math.sqrt(radius * radius + height * height);
}
}

/**
A class that represents a cylinder and can calculate its volume and
surface area.
*/
public class Cylinder
{
private double radius;
private double height;

/**
Creates a new cylinder of given height and radius.
@param radius the radius
@param height the height
*/
public Cylinder(double radius, double height)
{
this.radius = radius;
this.height = height;
}

/**
Calculates the volume of a cylinder.
@return the volume of the cylinder
*/
public double getVolume()
{
return Math.PI * radius * radius * height;
}

© John Wiley & Sons, Inc. All rights reserved. 18


/**
Calculates the surface area of the cylinder.
@return the surface area of the cylinder
*/
public double getSurface()
{
return 2 * Math.PI * radius * (radius + height);
}
}

/**
A class that represents a sphere and can calculate its volume and surface area.
*/
public class Sphere
{
private double radius;

/**
Creates a sphere of a given radius.
@param radius the radius
*/
public Sphere(double radius)
{
this.radius = radius;
}

/**
Calculates the volume of the sphere.
@return the volume of the sphere.
*/
public double getVolume()
{
return 4.0 / 3.0 * Math.PI * Math.pow(radius, 3);
}

/**
Calculates the surface area of the sphere.
@return the volume of the sphere.
*/
public double getSurface()
{
return 4.0 * Math.PI * radius * radius;
}
}

import java.util.Scanner;

public class GeometryTest


{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter radius: ");
double radius = in.nextDouble();

© John Wiley & Sons, Inc. All rights reserved. 19


System.out.println("Enter height: ");
double height = in.nextDouble();

Sphere sphere = new Sphere(radius);


Cone cone = new Cone(radius, height);
Cylinder cylinder = new Cylinder(radius, height);

System.out.println("Sphere volume: " + sphere.getVolume());


System.out.println("Sphere surface: " + sphere.getSurface());
System.out.println("Cylinder volume: " + cylinder.getVolume());
System.out.println("Cylinder surface: " + cylinder.getSurface());
System.out.println("Cone volume: " + cone.getVolume());
System.out.println("Cone surface: " + cone.getSurface());
}
}

P8.16

import java.util.ArrayList;

/**
A simulated cash register that tracks the item count and
the total amount due.
*/
public class CashRegisterModified
{
private ArrayList<Double> itemPrices;

/**
Constructs a cash register with cleared item totals
*/
public CashRegisterModified()
{
itemPrices = new ArrayList<Double>();
}

/**
Adds an item to this cash register.
@param price the price of this item
*/
public void addItem(double price)
{
itemPrices.add(price);
}

/**
Gets the price of all items of the current sale.
@return the total price
*/
public double getTotal()
{
double total = 0.0;
for (double price : itemPrices)
{
total += price;

© John Wiley & Sons, Inc. All rights reserved. 20


}
return total;
}

/**
Gets the number of items in the current sale.
@return the item count
*/
public int getCount()
{
return itemPrices.size();
}

/**
Clears the item count and the total.
*/
public void clear()
{
itemPrices = new ArrayList<Double>();
}

/**
Displays the prices of all items in the current sale.
*/
public void displayAll()
{
for (int i = 0; i < itemPrices.size(); i++)
{
System.out.println(itemPrices.get(i));
}
}
}

P8.17

/**
A simulated cash register that tracks the item count and
the total amount due.
*/
public class CashRegister
{
private int itemCount;
private int totalPrice;

/**
Constructs a cash register with cleared item totals
*/
public CashRegister()
{
itemCount = 0;
totalPrice = 0;
}

/**
Adds an item to this cash register.

© John Wiley & Sons, Inc. All rights reserved. 21


@param price the price of this item
*/
public void addItem(double price)
{
totalPrice += (int) (price * 100);
itemCount++;
}

/**
Gets the price of all items of the current sale.
@return the total price
*/
public double getTotal()
{
return totalPrice / 100.0;
}

/**
Gets the number of items in the current sale.
@return the item count
*/
public int getCount()
{
return itemCount;
}

/**
Clears the item count and the total.
*/
public void clear()
{
itemCount = 0;
totalPrice = 0;
}
}

P8.18

/**
A simulated cash register that tracks the item count,
the total amount due, and total sales.
*/
public class CashRegisterModified
{
private int itemCount;
private double totalPrice;
private int salesCount;
private double totalSales;

/**
Constructs a cash register with cleared item totals
*/
public CashRegisterModified()
{
itemCount = 0;

© John Wiley & Sons, Inc. All rights reserved. 22


totalPrice = 0;
salesCount = 0;
totalSales = 0;
}

/**
Adds an item to this cash register.
@param price the price of this item
*/
public void addItem(double price)
{
totalPrice += price;
totalSales += price;
itemCount++;
salesCount++;
}

/**
Gets the price of all items of the current sale.
@return the total price
*/
public double getTotal()
{
return totalPrice;
}

/**
Gets the number of items sold in a day.
@return the item count
*/
public int getSalesCount()
{
return salesCount;
}

/**
Gets the price of all items sold in a day.
@return the total price
*/
public double getSalesTotal()
{
return totalSales;
}

/**
Gets the number of items in the current sale.
@return the item count
*/
public int getCount()
{
return itemCount;
}

/**
Clears the item count and the total.
*/
public void clear()

© John Wiley & Sons, Inc. All rights reserved. 23


{
itemCount = 0;
totalPrice = 0;
}

/**
Clears the sales and count total.
*/
public void resetSales()
{
clear();
salesCount = 0;
totalSales = 0;
}
}

P8.19

/**
A class that has both a checking and savings account.
*/
public class Portfolio
{
private BankAccount checking;
private BankAccount savings;

/**
Initializes a new portfolio with empty checking and savings
balances.
*/
public Portfolio()
{
checking = new BankAccount();
savings = new BankAccount();
}

/**
Adds amount to the appropriate account.
@param amount amount of money to add
@param account "S" for savings "C" for checking
*/
public void deposit(double amount, String account)
{
if (account.equals("S"))
{
savings.deposit(amount);
}
if (account.equals("C"))
{
checking.deposit(amount);
}
}

/**
Removes amount from the appropriate account.

© John Wiley & Sons, Inc. All rights reserved. 24


@param amount amount of money to withdraw
@param account "S" for savings "C" for checking
*/
public void withdraw(double amount, String account)
{
if (account.equals("S"))
{
savings.withdraw(amount);
}
if (account.equals("C"))
{
checking.withdraw(amount);
}
}

/**
Transfers amount from one account to the other
@param amount amount of money to transfer
@param account "S" for savings "C" for checking for which account
the money is taken from.
*/
public void transfer(double amount, String account)
{
if (account.equals("S"))
{
savings.withdraw(amount);
checking.deposit(amount);
}
if (account.equals("C"))
{
checking.withdraw(amount);
savings.deposit(amount);
}
}

/**
Gets the current balances of an account.
@param account "S" for savings "C" for checking to indicate account
the money is taken from.
*/
public double getBalance(String account)
{
if (account.equals("S"))
{
System.out.println("Savings: " + savings.getBalance());
}
if (account.equals("C"))
{
System.out.println("Checking: " + checking.getBalance());
}
}
}

P8.20

This solution has two classes: Country and LargestCountry:

© John Wiley & Sons, Inc. All rights reserved. 25


/**
A class to hold relevant country information.
*/
public class Country
{
private String name;
private int population;
private double area;

/**
Initializes the country with the given inputs.
@param name the name to set
@param population the population to set
@param area the area to set
*/
public Country(String name, int population, double area)
{
this.name = name;
this.population = population;
this.area = area;
}

/**
Prints the relevant country information.
*/
public void printCountry()
{
System.out.printf("Name: %s\nPopulation %d\nArea: %f\n", name,
population, area);
}

/**
Reports the population density
@return the population density
*/
public double getPopulationDensity()
{
if (area != 0)
{
return population / area;
}
else
{
return 0;
}
}

/**
Calculates which country has larger population.
@param b the other country
@return true if this is larger than b
*/
public boolean largerPopulation(Country b)
{
return this.population > b.population;

© John Wiley & Sons, Inc. All rights reserved. 26


}

/**
Calculates which country has larger population density.
@param b the other country
@return true if this is larger than b
*/
public boolean largerDensity(Country b)
{
return this.getPopulationDensity() > b.getPopulationDensity();
}

/**
Calculates which country has larger area.
@param b the other country
@return true if this is larger than b
*/
public boolean largerArea(Country b)
{
return this.area > b.area;
}
}

import java.util.Scanner;

public class LargestCountry


{
/**
Reads a country in from input.
@return a valid country or else null if no country entered
*/
public static Country readCountry()
{
System.out.println("Enter country name (\"quit\" to quit): ");
Scanner in = new Scanner(System.in);
String name = in.next();
if (!name.equals("quit"))
{
System.out.println("Enter country population: ");
int population = in.nextInt();
System.out.println("Enter country area: ");
double area = in.nextDouble();
return new Country(name, population, area);
}
return null;
}

public static void main(String[] args)


{
// Initialize basic countries
Country largestArea = new Country("", 0, 0);
Country largestPopulation = new Country("", 0, 0);
Country largestDensity = new Country("", 0, 0);

Country b = readCountry();
while (b != null)
{

© John Wiley & Sons, Inc. All rights reserved. 27


if (b.largerArea(largestArea))
{
largestArea = b;
}
if (b.largerPopulation(largestPopulation))
{
largestPopulation = b;
}
if (b.largerDensity(largestDensity))
{
largestDensity = b;
}
b = readCountry();
}
System.out.println("Largest area: ");
largestArea.printCountry();
System.out.println("Largest population: ");
largestPopulation.printCountry();
System.out.println("Largest population density: ");
largestDensity.printCountry();
}
}

P8.21

This solution has two classes, Message and TestMessage:

/**
A class that models an e-mail message.
*/
public class Message
{
private String recipient;
private String sender;
private String messageText;

/**
Takes the sender and recipient
@param recipient the recipient
@param sender the sender
*/
public Message(String recipient, String sender)
{
this.recipient = recipient;
this.sender = sender;
messageText = "";
}

/**
Appends a line of text to the message body.
@param line the line to append
*/
public void append(String line)
{

© John Wiley & Sons, Inc. All rights reserved. 28


messageText = messageText + "\n" + line;
}

/**
Makes the message into one long string.
*/
public String toString()
{
return "From: " + sender + "\nTo: " + recipient + "\n" + messageText;
}

/**
Prints the message text.
*/
public void print()
{
System.out.print(this.toString());
}
}

public class TestMessage


{
public static void main(String[] args)
{
Message email = new Message("Harry Morgan", "Rudolf Reindeer");
email.append("Dear so and so,");
email.append("It is my great pleasure to");
email.append("write you an email.");
email.append("");
email.append("Goodbye!");
email.print();
}
}

P8.22

import java.util.ArrayList;

/**
A class that stores e-mail messages.
*/
public class Mailbox
{
private ArrayList<Message> messages;

/**
Initializes an empty mailbox.
*/
public Mailbox()
{
messages = new ArrayList<Message>();
}

/**

© John Wiley & Sons, Inc. All rights reserved. 29


Adds a new message.
@param m the message
*/
public void addMessage(Message m)
{
messages.add(m);
}

/**
Gets the ith message.
@param i the message number to get
@return the ith message
*/
public Message getMessage(int i)
{
return messages.get(i);
}

/**
Removes the ith message.
@param i the message number to remove
*/
public void removeMessage(int i)
{
messages.remove(i);
}
}

P8.23

import java.util.Scanner;

/**
A class that discounts $10 on the next purchase after $100 in purchases.
*/
public class Discount
{
public static double total;
public static double discountTally;

public static void makePurchase(double amount)


{
if (discountReached())
{
total = total + amount - 10.0;
discountTally = amount - 10.0;
}
else
{
total = total + amount;
discountTally = discountTally + amount;
}
}

public static boolean discountReached()

© John Wiley & Sons, Inc. All rights reserved. 30


{
if (discountTally >= 100)
{
return true;
}
else
{
return false;
}
}

public static void main(String[] args)


{
boolean more = true;
total = 0;
discountTally = 0;
do
{
Scanner in = new Scanner(System.in);
System.out.println("Please enter a purchase amount, -1 to quit: ");
double input = in.nextDouble();

if (input == -1)
{
more = false;
}
else
{
makePurchase(input);
}
}
while (more);

System.out.println("Total sale, including discounts : " + total);


}
}

P8.24

import java.util.Scanner;
import java.util.ArrayList;

/**
A class that discounts $10 on the next purchase after $100 in purchases.
*/
public class Discount
{
public static double total = 0;
public static double discountTally = 0;
private static ArrayList<Integer> stores = new ArrayList<Integer>();

public static void makePurchase(double amount)


{
if (discountReached())
{
total = total + amount - 10;

© John Wiley & Sons, Inc. All rights reserved. 31


discountTally = amount - 10;
stores = new ArrayList<Integer>();
}
else
{
total = total + amount;
discountTally = discountTally + amount;
}
}

public static boolean discountReached()


{
if ((discountTally >= 100) && (stores.size() >= 3))
{
return true;
}
else
{
return false;
}
}

public static void main(String[] args)


{
boolean more = true;

do
{
Scanner in = new Scanner(System.in);
System.out.println("Please enter a purchase amount, -1 to quit: ");
double input = in.nextDouble();

if (input != -1)
{
System.out.println("Please enter a store number from 1 - 20: ");
int visit = in.nextInt();
stores.add(visit);
int i = 0;
while (i < stores.size() - 1)
{
if (stores.get(i) == stores.get(i + 1))
{
stores.remove(stores.get(i + 1));
}
else
{
i++;
}
}
makePurchase(input);
}
else
{
more = false;
}
}
while (more);

© John Wiley & Sons, Inc. All rights reserved. 32


System.out.println("Total sale, including discounts : " + total);
}
}

P8.25

There are two classes in this solution, Cannonball and FireCannonball:

/**
A class that simulates a cannonball firing in the air.
*/
public class Cannonball
{
private double xPos;
private double yPos;
private double xVel;
private double yVel;

private static final double GRAVITY = -9.81;

/**
Initializes a cannonball to the given weight and x position.
@param xPos the x position
*/
public Cannonball(double xPos)
{
this.xPos = xPos;
this.yPos = 0;
}

/**
Moves the cannonball given its current velocity, also updates
velocity for gravity.
@param sec the seconds the move simulates
*/
public void move(double sec)
{
xPos += xVel * sec;
yPos += yVel * sec;
yVel += GRAVITY * sec;
}

/**
Gets the x position of the cannonball.
@return the x position of the cannonball
*/
public double getX()
{
return xPos;
}

/**
Gets the y position of the cannonball.
@return the y position of the cannonball
*/
public double getY()

© John Wiley & Sons, Inc. All rights reserved. 33


{
return yPos;
}

/**
Simulates a cannonball being fired given the initial angle and
velocity.
@param alpha the angle to fire
@param v the velocity to fire at
*/
public void shoot(double alpha, double v)
{
xVel = v * Math.cos(alpha);
yVel = v * Math.sin(alpha);

do
{
move(0.1);
System.out.printf("xpos: %f, ypos: %f\n", xPos, yPos);
} while (yPos > 0);
}
}

import java.util.Scanner;

/**
A class that prompts the user for an angle and velocity to fire a
cannonball.
*/
public class FireCannonball
{
public static void main(String[] args)
{
System.out.println("Please enter a starting angle: ");
Scanner in = new Scanner(System.in);
double angle = in.nextDouble();

System.out.println("Please enter a firing velocity: ");


double velocity = in.nextDouble();

Cannonball ball = new Cannonball(0.0);


ball.shoot(angle, velocity);
}
}

P8.26

public class Resistor


{
double nominalResistance;
double tolerance;
double actualResistance;

public Resistor(double rn, double t)

© John Wiley & Sons, Inc. All rights reserved. 34


{
nominalResistance = rn;
tolerance = t;
actualResistance = rn * (1 + (2.0 * Math.random() / Math.random() - 1)
* t / 100.0);
}

public double getNominalResistance()


{
return nominalResistance;
}

public double getTolerance()


{
return tolerance;
}

public double getActualResistance()


{
return actualResistance;
}

public static void main(String[] args)


{
final int NRESISTOR = 10;

for (int i = 1; i <= NRESISTOR; i++)


{
Resistor r = new Resistor(330, 10);
System.out.println(i + " " + r.getNominalResistance() + " "
+ r.getTolerance() + " " + r.getActualResistance() );
}
}
}

P8.27

public class Resistor


{

double nominalResistance;
double tolerance;
double actualResistance;

public Resistor(double rn, double t)


{
nominalResistance = rn;
tolerance = t;
actualResistance = rn * (1 + (2.0 * Math.random() / Math.random()- 1)
* t / 100.0);
}

public double getNominalResistance()


{
return nominalResistance;

© John Wiley & Sons, Inc. All rights reserved. 35


}

public double getTolerance()


{
return tolerance;
}

public double getActualResistance()


{
return actualResistance;
}

public String digitColor(String digit)


{
if (digit == "0") { return "black"; }
else if (digit == "1") { return "brown"; }
else if (digit == "2") { return "red"; }
else if (digit == "3") { return "orange"; }
else if (digit == "4") { return "yellow"; }
else if (digit == "5") { return "green"; }
else if (digit == "6") { return "blue"; }
else if (digit == "7") { return "violet"; }
else if (digit == "8") { return "gray"; }
else if (digit == "9") { return "white"; }
else { return "?"; }
}

public String multiplierColor(int exponent)


{
if (exponent == 1) { return "black"; }
else if (exponent == 2) { return "brown"; }
else if (exponent == 3) { return "red"; }
else if (exponent == 4) { return "orange"; }
else if (exponent == 5) { return "yellow"; }
else if (exponent == 6) { return "green"; }
else if (exponent == 7) { return "blue"; }
else if (exponent == 8) { return "violet"; }
else if (exponent == 9) { return "gray"; }
else if (exponent == 10) { return "white"; }
else if (exponent == 0) { return "gold"; }
else if (exponent == -1) { return "silver"; }
else { return "?"; }
}

public boolean approxEqual(double x, double y)


{
final double EPSILON = 1E-10;
return Math.abs(x - y) < EPSILON;
}

public String toleranceColor(double tolerance)


{
if (approxEqual(tolerance, 1)) { return "brown"; }
else if (approxEqual(tolerance, 2)) { return "red"; }
else if (approxEqual(tolerance, 0.5)) { return "green"; }
else if (approxEqual(tolerance, 0.25)) { return "blue"; }
else if (approxEqual(tolerance, 0.1)) { return "violet"; }

© John Wiley & Sons, Inc. All rights reserved. 36


else if (approxEqual(tolerance, 0.05)) { return "gray"; }
else if (approxEqual(tolerance, 5)) { return "gold"; }
else if (approxEqual(tolerance, 10)) { return "silver"; }
else if (approxEqual(tolerance, 20)) { return "none"; }
else { return "?"; }
}

public String colorBands()


{
String output = "";

System.out.print("debug " + output );


String color1 = digitColor(output.substring(0, 1));
String color2 = digitColor(output.substring(2, 1));

String exponent = output.substring(4, output.length() - 4);

int exponentValue = 5;

String color3 = multiplierColor(exponentValue);


String color4 = toleranceColor(tolerance);
return color1 + " " + color2 + " " + color3 + " " + color4;
}

public static void main(String[] args)


{
Scanner in = new Scanner(System.in);

System.out.print("Resistance: ");
double resistance = in.nextDouble();

System.out.print("Tolerance in percent: ");


double tolerance= in.nextDouble();
Resistor r = new Resistor(resistance, tolerance);

System.out.print(r.colorBands());

}
}

P8.28

public class Resistor


{
double nominalResistance;
double tolerance;
double actualResistance;

public Resistor()
{
nominalResistance = 0;
tolerance = 0;
actualResistance = 0;

© John Wiley & Sons, Inc. All rights reserved. 37


}

public Resistor(double rn, double t)


{
nominalResistance = rn;
tolerance = t;
actualResistance = rn * (1 + (2.0 * Math.random() / Math.random() - 1)
* t / 100.0);
}

public double getNominalResistance()


{
return nominalResistance;
}

public double getTolerance()


{
return tolerance;
}

public double getActualResistance()


{
return actualResistance;
}
}

public class VoltageDivider


{
Resistor r1 = new Resistor();
Resistor r2 = new Resistor();

public VoltageDivider(Resistor first, Resistor second)


{
r1 = first;
r2 = second;
}

public double getNominalGain()


{
return r2.getNominalResistance() / (r1.getNominalResistance()
+ r2.getNominalResistance());
}

public double getActualGain()


{
return r2.getActualResistance() / (r1.getActualResistance()
+ r2.getActualResistance());
}

public static void main(String[] args)


{
final int NCIRCUIT = 10;

for (int i = 1; i <= NCIRCUIT; i++)


{
Resistor r1 = new Resistor(330, 5);
Resistor r2 = new Resistor(750, 5);

© John Wiley & Sons, Inc. All rights reserved. 38


VoltageDivider divider = new VoltageDivider(r1, r2);
System.out.println( i + " " + divider.getNominalGain() + " "
+ divider.getActualGain() );
}
}
}

© John Wiley & Sons, Inc. All rights reserved. 39


Another random document with
no related content on Scribd:
Þar sem um Hjaltlands
Heimkynni þögul
Norðurhafs öldur
Ólmar freyða,
Stynja þar stormar,
Stúra brimboðar,
Lifandi veru
Líkar sorgröddum.

52. The raven was regarded as sacred, and greatly venerated by the old Norse Vikings, who
had always one or two of these birds in their ships. When setting out on marauding
expeditions the raven was let loose and his flight followed by the bold voyagers, in the
belief that he led them to war and victory. These birds it was supposed lived to a
fabulous age. Odin’s shield had a raven on it, and so had the Landeyda or battle-flag of
Sigurd, which ever led to victory, although its bearer was doomed to die. Hialtland is the
ancient name of Shetland. The Norse rovers thought it a disgrace to die in their beds in
peace; and when they found their end approaching, clad in armour, had themselves
carried on board their ships which were then set fire to and sent adrift, that the old
heroes might die, as they had lived, on the ocean, and thence worthily rise to Valhalla.

53. The “Death of the Old Norse King,” translated into Icelandic verse by the Rev. Olaf
Pálsson.

54. A rix dollar is equal in value to 2/3 English. A skilling is a fraction more than a farthing.

55. Extracted from the postscript to Mr. William Longman’s “Suggestions for the
Exploration of Iceland”—an address delivered to the members of the Alpine Club, of
which he is Vice-President.—Longman & Co., 1861.

56. This chapter, written in December 1859, has already appeared in the pages of a
periodical.—A.J.S.

57. These journals, while admitting, in a general though apologetic way, that great evils exist
in connection with slavery, yet, somehow, on every occasion, systematically and
persistently uphold pro-slavery measures and interests.

58. Fuller information and subsequent events in America have justified and amply
confirmed this estimate of Brown, formed at the time. Having had access to documents,
published and unpublished, and being in a position to judge, we would confidently refer
the reader to a volume of 452 pp. 8vo., since published by Smith, Elder & Co.—“The
Life and Letters of Captain John Brown, edited by Richard D. Webbe”—as presenting a
fair statement of the facts of the case. From Brown’s deeds and words, therein recorded,
it will be clearly seen, how calm, noble and dignified was the bearing of the man whom
short-sighted trimmers, on both sides the Atlantic, have attempted to brand as a fanatic.

59. See “Lay of the Vikings,” p. 278.

60. The antiquarian book to which we have already referred, erroneously attributes the
discovery to Garder, a Dane of Swedish origin. Our authority is Gísli Brynjúlfsson, the
Icelandic poet, now resident in Copenhagen, to whose kindness we are also indebted for
the copy of this work which we possess.

61. For these last, we would refer to Thorpe’s “Yuletide Stories,” Dasent’s “Popular Tales
from the Norse,” our own Nursery Lore, and to preceding Stories and Tales in this
appendix.

62. Mr. Dasent has since published an admirable translation of “Njal’s Saga,” which presents
a vivid picture of life in Iceland at the end of the tenth century.

63. See the preceding specimens of old Icelandic poetry.


Transcriber’s Notes
Note: Use of Icelandic diacritics by the author/printer is very inconsistent,
and usage has partly been regularized. All types of diacritics which have
historically not been used for Icelandic have been changed, as noted below.
Spelling of individual words has also been normalized where there was
variation. Otherwise, spelling of Icelandic words has been retained.
Obvious misspellings of English words and printer’s errors have been
changed. Hyphenation inconsistencies have been retained, except in cases
where a predominant form has been found.
Pg. vii: Proper name consistency: ‘Skaptar Jökel’ to ‘Skaptár Jökul’

Pg. vii: Punctuation consistency: ‘on Northern Subjects.’ to ‘on Northern Subjects’—Removed
period at end of TOC entry

Pg. vii: Proper name consistency: ‘Kötluja’s’ to ‘Kötlugjá’s’

Pg. vii: Corrected accent: ‘Sölar’ to ‘Sólar’

Pg. viii: Corrected accent: ‘Bruarâ’ to ‘Bruará’

Pg. viii: Proper name consistency: ‘Kötlujá’ to ‘Kötlugjá’

Pg. 12: Repeated word: ‘in in the time’ to ‘in the time’

Pg. 17: Hyphenation consistency: ‘on-goings’ to ‘ongoings’

Pg. 23: Hyphenation consistency: ‘flag-staff ’ to ‘flagstaff ’

Pg. 25: Corrected typo: ‘posseses’ to ‘possesses’

Pg. 26: Hyphenation consistency: ‘lambskin’ to ‘lamb-skin’

Pg. 29: Punctuation fix: ‘Mr’ to ‘Mr.’

Pg. 31: Punctuation fix: ‘Mr’ to ‘Mr.’

Pg. 37: Hyphenation consistency: ‘zigzagging’ to ‘zig-zagging’

Pg. 38: Corrected typo: ‘ROCKSOFF--’ to ‘ROCKS--OFF’

Pg. 43: Proper name consistency: ‘Aladin’ to ‘Aladdin’

Pg. 47: Proper name consistency: ‘Guldbringe’ to ‘Guldbringu’


Pg. 48: Punctuation fix: ‘their nests are lined’ to ‘their nests are lined.’—Added missing period
at para end

Pg. 49: Proper name consistency: ‘Gudmundson’ to ‘Gudmundsson’

Pg. 49: Proper name consistency: ‘Hjaltelin’ to ‘Hjaltalin’

Pg. 52: Punctuation fix: ‘cleanliness comfort and refinement’ to ‘cleanliness, comfort and
refinement’—Added missing comma

Pg. 55: Repeated word: ‘the the’ to ‘the’

Pg. 60: Corrected typo: ‘fastideous’ to ‘fastidious’

Pg. 62: Hyphenation consistency: ‘fire-side’ to ‘fireside’

Pg. 64: Corrected typo: ‘substanial’ to ‘substantial’

Pg. 64: Corrected typo: ‘supplimented’ to ‘supplemented’

Pg. 65: Corrected typo: ‘órfjálsum’ to ‘ófrjálsum’

Pg. 66: Corrected typo: ‘sgiri’ to ‘sigri’

Pg. 66: Hyphenation consistency: ‘church-yard’ to ‘churchyard’

Pg. 66: Hyphenation consistency: ‘buttercups’ to ‘butter-cups’

Pg. 66: Proper name consistency: ‘Hjaltelin’ to ‘Hjaltalin’

Pg. 66: Corrected accent: ‘höggí’ to ‘höggi’

Pg. 70: Corrected typo: ‘at each others’ to ‘at each other’s’—Added missing apostrophe

Pg. 76: Hyphenation consistency: ‘sea pink’ to ‘sea-pink’

Pg. 78: Hyphenation consistency: ‘Oxerâ’ to ‘Oxerá’

Pg. 81: Proper name consistency: ‘ALMANNAGJA’ to ‘ALMANNA GJÁ’

Pg. 81: Proper name consistency: ‘ALMANNAGJA’ to ‘ALMANNA GJÁ’

Pg. 82: Proper name consistency: ‘Oxerâ’ to ‘Oxerá’

Pg. 83: Proper name consistency: ‘OXERA’ to ‘OXERÁ’

Pg. 84: Proper name consistency: ‘Shakspeare’s ’ to ‘Shakspere’s ’

Pg. 85: Corrected accent: ‘tuns’ to ‘túns’


Pg. 86: Punctuation fix: ‘conceivable direction,’ to ‘conceivable direction.’—Comma at para
end

Pg. 90: Proper name consistency: ‘OXERA’ to ‘OXERÁ’

Pg. 94: Hyphenation consistency: ‘hillside’ to ‘hill-side’

Pg. 96: Hyphenation consistency: ‘Lauger-vatn’ to ‘Laugervatn’

Pg. 96: Hyphenation consistency: ‘Apa-vatn’ to ‘Apavatn’

Pg. 96: Hyphenation consistency: ‘Lauger-vatn’ to ‘Laugervatn’

Pg. 97: Hyphenation consistency: ‘stockfish’ to ‘stock-fish’

Pg. 102: Corrected accent: ‘thèr’ to ‘thér’

Pg. 102: Corrected accent: ‘thèr’ to ‘thér’

Pg. 105: Corrected accent: ‘BRUARA´’ to ‘BRUARÁ’

Pg. 106: Hyphenation consistency: ‘head-land’ to ‘headland’

Pg. 112: Proper name consistency: ‘Skaptar’ to ‘Skaptár’

Pg. 115: Hyphenation consistency: ‘day-light’ to ‘daylight’

Pg. 116: Spelling consistency: ‘Igdrasill’ to ‘Yggdrasill’

Pg. 117: Corrected typo: ‘minature’ to ‘miniature’

Pg. 125: Corrected accent: ‘Landnàmabok’ to ‘Landnámabok’

Pg. 129: Corrected typo: ‘asteriods’ to ‘asteroids’

Pg. 134: Proper name consistency: ‘SKAPTAR’ to ‘SKAPTÁR’

Pg. 135: Proper name consistency: ‘Skaptar’ to ‘Skaptár’

Pg. 138: Missing punctuation: ‘Faröe Islands. pp 30’ to ‘Faröe Islands, pp 30’—Period for
comma

Pg. 140: Hyphenation consistency: ‘Oxerâ’ to ‘Oxerá’

Pg. 146: Corrected typo: ‘girnmunst’ to ‘girnumst’

Pg. 147: Corrected typo: ‘vir’ to ‘vér’

Pg. 148: Proper name consistency: ‘Rändrop’ to ‘Randröp’


Pg. 148: Proper name consistency: ‘Rändrop’ to ‘Randröp’

Pg. 154: Spelling consistency: ‘amtmen’ to ‘amptmen’

Pg. 156: Punctuation fix: ‘312-323’ to ‘312-323.’—Added missing period

Pg. 157: Corrected accent: ‘Thiöthölfr’ to ‘Thióthólfr’

Pg. 158: Corrected typo: ‘Kleiservatn’ to ‘Kleifervatn’

Pg. 159: Corrected typo: ‘Bryujúlfsson’ to ‘Brynjúlfsson’

Pg. 161: Corrected accent: ‘JOKUL’ to ‘JÖKUL’—Added diaeresis for consistency

Pg. 163: Corrected typo: ‘Elldborg’ to ‘Eldborg’

Pg. 163: Apostrophe usage: ‘KÖTLUGJÁS’ to ‘KÖTLUGJÁ’S’

Pg. 164: Hyphenation consistency: ‘waterfloods’ to ‘water-floods’

Pg. 166: Hyphenation consistency: ‘waterfloods’ to ‘water-floods’

Pg. 166: Corrected accent: ‘Kötlugjâ’ to ‘Kötlugjá’

Pg. 166: Hyphenation consistency: ‘waterfloods’ to ‘water-floods’

Pg. 167: Corrected typo: ‘Eyaffialla’ to ‘Eyafialla’

Pg. 167: Proper name consistency: ‘Skaptafells-syssel’ to ‘Skaptáfells-syssel’

Pg. 167: Quote placement: ‘has ever occurred.’ to ‘has ever occurred.”’—Added missing close-
quote to quote end

Pg. 171: Corrected typo: ‘Hsfrsey’ to ‘Hafrsey’

Pg. 171: Hyphenation consistency: ‘west-ward’ to ‘westward’

Pg. 171: Hyphenation consistency: ‘east-ward’ to ‘eastward’

Pg. 171: Punctuation fix: ‘issue from Kötlugjá,’ to ‘issue from Kötlugjá.’—Comma for period

Pg. 172: Corrected typo: ‘counrty’ to ‘country’

Pg. 173: Hyphenation consistency: ‘over-flowed’ to ‘overflowed’

Pg. 176: Duplicate word: ‘the the’ to ‘the’

Pg. 176: Proper name consistency: ‘Guldbringé’ to ‘Guldbringu’


Pg. 176: Quote placement: ‘80 to 90 miles distant.”’ to ‘80 to 90 miles distant.’—Removed
extra close-quote

Pg. 177: Proper name consistency: ‘Guldbringé’ to ‘Guldbringu’

Pg. 177: Proper name consistency: ‘Markarflíót’ to ‘Markarfliót’

Pg. 178: Corrected accent: ‘aúdug’ to ‘audug’

Pg. 178: Corrected accent: ‘Fiflskù’ to ‘Fiflsku’

Pg. 178: Spelling consistency: ‘thángast’ to ‘thángad’

Pg. 182: Proper name consistency: ‘Huc’ to ‘Huk’

Pg. 183: Corrected accent: ‘skörsmidr’ to ‘skórsmidr’

Pg. 184: Corrected accent: ‘JOKUL’ to ‘JÖKUL’—Added diaeresis for consistency

Pg. 184: Corrected accent: ‘KOTLUGJA’ to ‘KÖTLUGJÁ’—Added diaeresis for consistency

Pg. 185: Corrected accent: ‘JOKUL’ to ‘JÖKUL’—Added diaeresis for consistency

Pg. 187: Proper name consistency: ‘SKAPTAR’ to ‘SKAPTÁR’

Pg. 189: Corrected typo: ‘distingushed’ to ‘distinguished’

Pg. 189: Extra punctuation: ‘lava. continued’ to ‘lava continued’—Removed extra period

Pg. 194: Proper name consistency: ‘Elldborg’ to ‘Eldborg’

Pg. 194: Proper name consistency: ‘Guldbringé’ to ‘Guldbringu’

Pg. 195: Proper name consistency: ‘Skeideræ’ to ‘Skeidará’

Pg. 195: Proper name consistency: ‘Skeideræ’ to ‘Skeidará’

Pg. 196: Proper name consistency: ‘Elldborg’ to ‘Eldborg’

Pg. 196: Corrected typo: ‘Heinabegr’s’ to ‘Heinaberg’s’

Pg. 196: Proper name consistency: ‘Skeidaræ’ to ‘Skeidarár’

Pg. 197: Proper name consistency: ‘Briedamerkasandr’ to ‘Breidamerkr-sandr’

Pg. 197: Proper name consistency: ‘Breidamerks’ to ‘Breidamerkr’

Pg. 190: Corrected typo: ‘Skuptaà’ to ‘Skaptaá’


Pg. 199: Hyphenation consistency: ‘Breida-fiords’ to ‘Breida fiords’

Pg. 205: Hyphenation consistency: ‘Buttercups’ to ‘Butter-cups’

Pg. 208: Chapter / TOC consistency: ‘N/A’ to ‘SEYDISFIORD, BY FARÖE TO LEITH’—


Added section heading where indicated in TOC

Pg. 209: Corrected typo: ‘similiar’ to ‘similar’

Pg. 215: Punctuation fix: ‘breakfast on board,’ to ‘breakfast on board.’—Comma at end of


sentence

Pg. 219: Corrected accent: ‘PALSSON’ to ‘PÁLSSON’

Pg. 220: Proper name consistency: ‘Kalfar’ to ‘Kalfur’

Pg. 221: Corrected typo: ‘dont’ to ‘don’t’

Pg. 221: Heading consistency: ‘II.--SÆMUND GETS’ to ‘II. SÆMUND GETS’—Removed


em-dash in section title to match other headers

Pg. 226: Proper name consistency: ‘A. J. S.’ to ‘A.J.S.’—Usually without spaces

Pg. 228: Hyphenation consistency: ‘Iceland moss’ to ‘Iceland-moss’

Pg. 228: Corrected typo: ‘wont’ to ‘won’t’

Pg. 229: Proper name consistency: ‘Skagafiörd’ to ‘Skagafiord’

Pg. 232: Corrected typo: ‘wont’ to ‘won’t’

Pg. 234: Proper name consistency: ‘Skagafiörd’ to ‘Skagafiord’

Pg. 234: Proper name consistency: ‘Skagafiörd’ to ‘Skagafiord’

Pg. 235: Proper name consistency: ‘Skagafiörd’ to ‘Skagafiord’

Pg. 236: Corrected typo: ‘dont’ to ‘don’t’

Pg. 239: Missing punctuation : ‘such a rib as this’ to ‘such a rib as this?’—Added missing ‘?’ at
para end

Pg. 241: Corrected typo: ‘wont’ to ‘won’t’

Pg. 242: Missing punctuation : ‘if she does’ to ‘“if she does’—Added missing opening
quotation mark

Pg. 252: Corrected typo: ‘Fairies’’ to ‘Fairies’


Pg. 254: Corrected typo: ‘dont’ to ‘don’t’

Pg. 255: Corrected typo: ‘parishoners’ to ‘parishioners’

Pg. 259: Quote placement: ‘little porridge pot.’ to ‘little porridge pot.”’—Added missing close-
quote at quote end

Pg. 260: Proper name consistency: ‘Volu’ to ‘Völu’

Pg. 260: Proper name consistency: ‘Vola’ to ‘Vala’—Nominative form corrected, see next
sentence

Pg. 260: Chapter / TOC consistency: ‘N/A’ to ‘FROM THE “VÖLUSPÁ”’—Added section
heading where indicated in TOC

Pg. 261: Corrected typo: ‘Gjallarborn’ to ‘Gjallarhorn’

Pg. 261: Corrected typo: ‘Nighögg’ to ‘Nidhögg’

Pg. 262: Chapter / TOC consistency: ‘N/A’ to ‘FROM THE “SÓLAR LJÓD”’—Added
section heading where indicated in TOC

Pg. 264: Quote placement: ‘this Sun’s Song!’ to ‘this Sun’s Song!”’—Added missing close-
quote at poem end

Pg. 265: Hyphenation consistency: ‘Niebelungen lied’ to ‘Niebelungen-lied’

Pg. 265: Corrected typo: ‘illustrions’ to ‘illustrious’

Pg. 265: Corrected typo: ‘mornfully’ to ‘mournfully’

Pg. 265: Quote placement: ‘Odin’s High Song’ to ‘“Odin’s High Song’—Added missing open-
quote at quote beginning

Pg. 265: Chapter / TOC consistency: ‘N/A’ to ‘FROM THE POEMS RELATING TO
SIGURD & BRYNHILD.’—Added section heading where indicated in TOC

Pg. 267: Missing punctuation : ‘the man speaks his mind’ to ‘the man speaks his mind.’—
Missing period added at stanza end

Pg. 269: Repeated word: ‘and and a straw-rick’ to ‘and a straw-rick’

Pg. 272: Missing punctuation: ‘live without crime’ to ‘live without crime.’—Missing period
added at stanza end

Pg. 274: Hyphenation consistency: ‘fire-wood’ to ‘firewood’

Pg. 274: Missing punctuation: ‘in her breast’ to ‘in her breast.’—Missing period added at
stanza end
Pg. 275: Corrected typo: ‘CXII’ to ‘XCII’

Pg. 277: Quote placement: ‘Gunlöd is weeping.’ to ‘Gunlöd is weeping.”’—Added missing


close-quote at poem end

Pg. 279: Corrected accent: ‘I’shafs’ to ‘Íshafs’

Pg. 279: Corrected accent: ‘O’lmar’ to ‘Ólmar’

Pg. 279: Proper name consistency: ‘Thorlakson’ to ‘Thorláksson’

Pg. 280: Corrected typo: ‘Ogöruggar’ to ‘Og öruggar’

Pg. 280: Corrected accent: ‘I’brjósti’ to ‘Í brjósti’

Pg. 280: Corrected accent: ‘A´’ to ‘Á’

Pg. 280: Corrected typo: ‘Horrfiun’ to ‘Horrfinn’

Pg. 280: Corrected accent: ‘I’vöggu’ to ‘Í vöggu’

Pg. 280: Corrected accent: ‘A´’ to ‘Á’

Pg. 280: Corrected typo: ‘þaðað’ to ‘það að’

Pg. 280: Corrected accent: ‘I’talska’ to ‘Ítalska’

Pg. 280: Corrected typo: ‘semheyri’ to ‘sem heyri’

Pg. 281: Corrected accent: ‘I’mekkjum’ to ‘Ímekkjum’

Pg. 281: Proper name consistency: ‘Hiatland’ to ‘Hialtland’

Pg. 281: Corrected typo: ‘Ogaldinn’ to ‘Og aldinn’

Pg. 281: Corrected accent: ‘þer’ to ‘þér’

Pg. 287: Corrected accent: ‘þèr’ to ‘þér’

Pg. 287: Corrected accent: ‘Skjött’ to ‘Skjótt’

Pg. 287: Corrected typo: ‘húrsa’ to ‘húsa’

Pg. 287: Corrected accent: ‘A´’ to ‘Á’

Pg. 287: Corrected typo: ‘bœði’ to ‘bæði’

Pg. 287: Corrected accent: ‘O´’ to ‘Ó’


Pg. 287: Corrected accent: ‘I´’ to ‘Í’

Pg. 287: Corrected accent: ‘Fo´tum’ to ‘Fótum’

Pg. 287: Corrected accent: ‘I´’ to ‘Í’

Pg. 287: Corrected accent: ‘bùið’ to ‘búið’

Pg. 288: Corrected typo: ‘Ogdökkvir’ to ‘Og dökkvir’

Pg. 288: Corrected typo: ‘Mæki’ to ‘Mœki’

Pg. 288: Corrected typo: ‘Irá’ to ‘Frá’

Pg. 288: Corrected accent: ‘O´mur’ to ‘Ómur’

Pg. 288: Corrected accent: ‘A´vita’ to ‘Á vita’

Pg. 288: Corrected accent: ‘O´ðins’ to ‘Óðins’

Pg. 288: Corrected accent: ‘A´skipi’ to ‘Á skipi’

Pg. 288: Corrected accent: ‘I´marar’ to ‘Í marar’

Pg. 288: Corrected accent: ‘I´niðmyrkvu’ to ‘Í niðmyrkvu’

Pg. 288: Corrected accent: ‘I´blindmyrkri’ to ‘Í blindmyrkri’

Pg. 288: Corrected accent: ‘I´ógna’ to ‘Í ógna’

Pg. 288: Corrected accent: ‘O´ðinn’ to ‘Óðinn’

Pg. 288: Corrected typo: ‘myskbláu’ to ‘myrkbláu’

Pg. 292: Corrected accent: ‘sỳsla’ to ‘sysla’

Pg. 292: Corrected accent: ‘sỳssel’ to ‘syssel’

Pg. 292: Punctuation fix: ‘lava,’ to ‘lava.’—Comma for period at entry end

Pg. 292: Corrected accent: ‘fljöt’ to ‘fljót’

Pg. 295: Proper name consistency: ‘Caesar’ to ‘Cæsar’

Pg. 304: Corrected typo: ‘flourshing’ to ‘flourishing’

Pg. 305: Proper name consistency: ‘eddas’ to ‘Eddas’—Capitalised elsewhere

Pg. 305: Proper name consistency: ‘eddas’ to ‘Eddas’—Capitalised elsewhere


Pg. 309: Hyphenation consistency: ‘Blaeberries’ to ‘Blae-berries’

Pg. 306: Proper name consistency: ‘Skalholt’ to ‘Skálholt’

Pg. 307: Spelling consistency: ‘Biarne’ to ‘Biarni’

Pg. 309: Proper name consistency: ‘Almanna Gjá’ to ‘Almannagjá’

Pg. 309: Proper name consistency: ‘Ailsay’ to ‘Ailsa’

Pg. 309: Hyphenation consistency: ‘Icedrift’ to ‘Ice-drift’

Pg. 309: Corrected accent: ‘Hrafnagjà’ to ‘Hrafnagjá’

Pg. 309: Corrected accent: ‘Bruarâ’ to ‘Bruará’

Pg. 309: Corrected accent: ‘Bruarâ’ to ‘Bruará’

Pg. 309: Proper name consistency: ‘Salvor’ to ‘Salvör’

Pg. 309: Proper name consistency: ‘Breidamerks’ to ‘Breidamerkr’

Pg. 310: Hyphenation consistency: ‘re-building’ to ‘rebuilding’

Pg. 310: Missing punctuation: ‘days 296’ to ‘days, 296’—Added comma before pg. number

Pg. 310: Missing punctuation: ‘26’ to ‘26.’—Added missing period at end of index subentry

Pg. 310: Hyphenation consistency: ‘Einars-drángr’ to ‘Einarsdrángr’

Pg. 311: Corrected pg. reference in index: ‘265’ to ‘266’

Pg. 311: Corrected accent: ‘tûns’ to ‘túns’

Pg. 311: Hyphenation consistency: ‘surefooted’ to ‘sure-footed’

Pg. 311: Proper name consistency: ‘Goldbringé’ to ‘Guldbringu’

Pg. 311: Proper name consistency: ‘Grœnvatn’ to ‘Grœnavatn’

Pg. 312: Hyphenation consistency: ‘Hvità’ to ‘Hvitá’

Pg. 312: Hyphenation consistency: ‘Icedrift’ to ‘Ice-drift’

Pg. 312: Hyphenation consistency: ‘In door occupations’ to ‘indoor occupations’

Pg. 312: Corrected typo: ‘Kleiservatn’ to ‘Kleifervatn’

Pg. 312: Hyphenation consistency: ‘Lighthouse’ to ‘Light-house’


Pg. 312: Proper name consistency: ‘Hrafna Gjá’ to ‘Hrafnagjá’

Pg. 312: Proper name consistency: ‘Logberg’ to ‘Lögberg’

Pg. 312: Proper name consistency: ‘Markarfliot’ to ‘Markarfliót’

Pg. 312: Proper name consistency: ‘Landfogged’ to ‘Landfoged’

Pg. 313: Corrected accent: ‘Oxerâ’ to ‘Oxerá’

Pg. 313: Punctuation fix: ‘Plain, 94.’ to ‘Plain, 94’—Extra punctuation at entry end

Pg. 313: Punctuation fix: ‘Plateau, 74.’ to ‘Plateau, 74’—Extra punctuation at entry end

Pg. 313: Punctuation fix: ‘Pits, 107.’ to ‘Pits, 107’—Extra punctuation at entry end

Pg. 314: Missing punctuation: ‘140’ to ‘140.’—Added missing period at end of index subentry

Pg. 314: Hyphenation consistency: ‘sea pinks’ to ‘sea-pinks’

Pg. 314: Corrected accent: ‘Thiöthölfr’ to ‘Thióthólfr’

Pg. 315: Corrected accent: ‘Tûn’ to ‘Tún’

Pg. 315: Corrected accent: ‘Bruarâ’ to ‘Bruará’

Pg. 315: Hyphenation consistency: ‘Waterfloods’ to ‘Water-floods’


*** END OF THE PROJECT GUTENBERG EBOOK PEN AND
PENCIL SKETCHES OF FARÖE AND ICELAND ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright
in these works, so the Foundation (and you!) can copy and
distribute it in the United States without permission and without
paying copyright royalties. Special rules, set forth in the General
Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and Redistributing Project


Gutenberg™ electronic works

1.A. By reading or using any part of this Project Gutenberg™


electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree to
abide by all the terms of this agreement, you must cease using
and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.

1.C. The Project Gutenberg Literary Archive Foundation (“the


Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project
Gutenberg™ works in compliance with the terms of this
agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms
of this agreement by keeping this work in the same format with
its attached full Project Gutenberg™ License when you share it
without charge with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it
away or re-use it under the terms of the Project Gutenberg
License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country where
you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of the
copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute


this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must, at
no additional cost, fee or expense to the user, provide a copy, a
means of exporting a copy, or a means of obtaining a copy upon
request, of the work in its original “Plain Vanilla ASCII” or other
form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You provide a full refund of any money paid by a user who
notifies you in writing (or by e-mail) within 30 days of receipt that
s/he does not agree to the terms of the full Project Gutenberg™
License. You must require such a user to return or destroy all
copies of the works possessed in a physical medium and
discontinue all use of and all access to other copies of Project
Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite
these efforts, Project Gutenberg™ electronic works, and the
medium on which they may be stored, may contain “Defects,”
such as, but not limited to, incomplete, inaccurate or corrupt
data, transcription errors, a copyright or other intellectual
property infringement, a defective or damaged disk or other
medium, a computer virus, or computer codes that damage or
cannot be read by your equipment.

You might also like