Fix errors specified in #410.

This commit is contained in:
Adam Brenecki 2013-11-16 19:40:06 +10:30
parent 13822f9c15
commit 8121793f32

View File

@ -26,7 +26,8 @@ import java.util.ArrayList;
// Import all classes inside of java.security package
import java.security.*;
// Each .java file contains one public class, with the same name as the file.
// Each .java file contains one outer-level public class, with the same name as
// the file.
public class LearnJava {
// A program must have a main method as an entry point
@ -84,7 +85,7 @@ public class LearnJava {
// Char - A single 16-bit Unicode character
char fooChar = 'A';
// Use final to make a variable immutable
// final variables can't be reassigned to another object
final int HOURS_I_WORK_PER_WEEK = 9001;
// Strings
@ -99,7 +100,7 @@ public class LearnJava {
System.out.println(bazString);
// Arrays
//The array size must be decided upon declaration
//The array size must be decided upon instantiation
//The format for declaring an array is follows:
//<datatype> [] <var name> = new <datatype>[<array size>];
int [] intArray = new int[10];
@ -161,10 +162,13 @@ public class LearnJava {
// Incrementations
int i = 0;
System.out.println("\n->Inc/Dec-rementation");
System.out.println(i++); //i = 1. Post-Incrementation
System.out.println(++i); //i = 2. Pre-Incrementation
System.out.println(i--); //i = 1. Post-Decrementation
System.out.println(--i); //i = 0. Pre-Decrementation
// The ++ and -- operators increment and decrement by 1 respectively.
// If they are placed before the variable, they increment then return;
// after the variable they return then increment.
System.out.println(i++); //i = 1, prints 0 (post-increment)
System.out.println(++i); //i = 2, prints 2 (pre-increment)
System.out.println(i--); //i = 1, prints 2 (post-decrement)
System.out.println(--i); //i = 0, prints 0 (pre-decrement)
///////////////////////////////////////
// Control Structures
@ -294,14 +298,14 @@ public class LearnJava {
trek.speedUp(3); // You should always use setter and getter methods
trek.setCadence(100);
// toString is a convention to display the value of this Object.
// toString returns this Object's string representation.
System.out.println("trek info: " + trek.toString());
} // End main method
} // End LearnJava class
// You can include other, non-public classes in a .java file
// You can include other, non-public outer-level classes in a .java file
// Class Declaration Syntax:
@ -319,7 +323,7 @@ class Bicycle {
String name; // default: Only accessible from within this package
// Constructors are a way of creating classes
// This is a default constructor
// This is a constructor
public Bicycle() {
gear = 1;
cadence = 50;
@ -327,7 +331,7 @@ class Bicycle {
name = "Bontrager";
}
// This is a specified constructor (it contains arguments)
// This is a constructor that takes arguments
public Bicycle(int startCadence, int startSpeed, int startGear, String name) {
this.gear = startGear;
this.cadence = startCadence;