public class ToTellTheTruth
{
public static void main(String[] args)
{
TrueStory.tell();
// TruthTables.print();
}
}
class TruthValues
{
public static final boolean
t = true,
f = false;
public static final Boolean
T = Boolean.TRUE,
F = Boolean.FALSE;
}
class TruthyEpigraphs
{
private static java.io.PrintStream out = System.out;
public static String getDumbledoreQuote()
{
String epigraph = "";
epigraph += " \"The truth.\" Dumbledore sighed. \"It is a beautiful\n";
epigraph += " and terrible thing, and should therefore be treated\n";
epigraph += " with great caution.\"\n";
epigraph += "\n- J.K. ROWLING, Harry Potter and the Sorcerer's Stone\n";
return epigraph;
}
public static String getContrapositionBlurb()
{
String epigraph = "";
epigraph += " In logic, contraposition is an inference that\n";
epigraph += " says that a conditional statement is logically\n";
epigraph += " equivalent to its contrapositive.\n";
epigraph += "\n - https://en.wikipedia.org/wiki/Contraposition\n";
return epigraph;
}
public static void putAtTop(String epigraph)
{
out.print(epigraph);
out.println();
out.println();
}
public static void putAtBottom(String epigraph)
{
out.println();
out.println();
out.print(epigraph);
}
public static void main(String[] args)
{
putAtTop(getDumbledoreQuote());
out.println("Lorem ipsum dolor sit amet, consectetur adipiscing elit,");
out.println("sed do eiusmod tempor incididunt ut labore et dolore");
out.println("magna aliqua.");
putAtBottom(getContrapositionBlurb());
}
}
class TrueStory
{
private static java.io.PrintStream out = System.out;
private static void tellAboutConstantVariables()
{
out.println("In the TruthValues class, the letters t, f, T,");
out.println("and F are the names of four constant variables.");
}
private static void tellAboutComparisonOperator()
{
out.print("The boolean expression t == f evaluates to ");
out.print(TruthValues.t == TruthValues.f);
out.println(".");
}
private static void tellAboutNotAndNotEqualsOperators()
{
out.print("The expression !(t != f) also evaluates to ");
out.print(!(TruthValues.t != TruthValues.f));
out.println(".");
}
private static void tellAboutSelectionOperator()
{
out.print("Similarly, t ? t : f evaluates to ");
out.print(TruthValues.t ? TruthValues.t : TruthValues.f);
out.print(", and \n!t ? !t : !f also evaluates to ");
out.print(!TruthValues.t ? !TruthValues.t : !TruthValues.f);
out.println(".");
}
private static void tellAboutWrapperClasses()
{
out.println("Values of type Boolean are not the same as values");
out.println("of type boolean. The latter (boolean) is one of");
out.println("the eight primitive Java data types. The former");
out.println("(Boolean) is like boolean but provides more");
out.println("capabilities, albeit at a price. In the curious");
out.println("case of the constant variables t, f, T, and F,");
out.println("T.equals(t) is an expression that evaluates to");
out.print(TruthValues.T.equals(TruthValues.t));
out.print(".");
out.println(" But t.equals(t) is not valid, because the");
out.println("value of t is of type boolean, which is a");
out.println("primitive type, and such a value is just only a");
out.println("value, nothing more. Values of types like Boolean,");
out.println("on the other hand, are things programmers call");
out.println("\"objects\". And objects may have methods like");
out.println("Boolean.equals() that can be invoked. Objects and");
out.println("the classes that define their types can also have");
out.println("meta values like Boolean.TRUE, the value of which");
out.print("(as you might have guessed) is ");
out.print(Boolean.TRUE);
out.println(".");
}
public static void tell()
{
out.println("True Story");
out.println();
TruthyEpigraphs.putAtTop(TruthyEpigraphs.getContrapositionBlurb());
tellAboutConstantVariables();
out.println();
tellAboutComparisonOperator();
tellAboutNotAndNotEqualsOperators();
tellAboutSelectionOperator();
out.println();
tellAboutWrapperClasses();
TruthyEpigraphs.putAtBottom(TruthyEpigraphs.getDumbledoreQuote());
}
public static void main(String[] args)
{
tell();
}
}