Pages

Draw me a . . .

README

See Also

Javadoc

Jargon

Code

Q&A

How do I print a double quote character?

Answer:

public class PrintDoubleQuote {

  // Used in main
  private static final char DQ1 = 34; // double quote is 34
  private static final char DQ2 = '"';

  public static void main(String[] args) {

    // Technique #1
    System.out.println("\"");

    // Technique #2
    System.out.println('"');
    
    // Technique #3
    System.out.println('\"');
    
    // Technique #4    
    System.out.println(DQ1);
    
    // More Examples
    System.out.println("\"I don't know,\" said Grasshopper.");
    System.out.println('"' + "I don't know," + '"' + " said Grasshopper.");
    System.out.println('\"' + "I don't know," + '\"' + " said Grasshopper.");
    System.out.println(DQ1 + "I don't know," + DQ2 + " said Grasshopper.");

    // Yet Another Example
    System.out.print('\"');
    System.out.print("I don't know,");
    System.out.print('"');
    System.out.print(" said Grasshopper.");
    System.out.print('\n');
  }
}

Notes

In Computer Science - An Interdisciplinary Approach,
  • Study the class UseArgument shown on page 7.
  • Note the escape sequences enumerated in the subsection Characters and strings on page 19, especially the escape sequence \".

If you are having trouble using PowerShell, javac, and java to compile and execute Java programs, review the information in the post With great power.

Exercises

Notes for AP Computer Science A (2017-2018) Students

  • Some if not all of the exercises below will be components of your first graded programming assignment.
  • You must include the following comment at the end of your program file named PrintProgSays.java:
    /*****************************************************
     * I understand that this is a graded programming
     * assignment and that I have been instructed to
     * do my own work and cite all forms of collaboration.
     * I understand that this means I should not look
     * at anyone else's source code and that I should
     * not share my source code with anyone.
     *
     * The Java program above is my own work. Unless I
     * have confessed in writing in this document,
     * I attest that I did not look at anyone else's
     * source code, I did not share my code with anyone,
     * and I have cited my sources, including all forms
     * of collaboration, in writing in this document.
     *
     * I understand that if I have claimed anyone else's
     * work as my own or if I shared my code with anyone,
     * then I will be penalized if caught, and I
     * understand what the penalties for cheating are.
     *
     * I understand that I must print a copy of this
     * document, sign it, and submit the signed document
     * before my work will be considered for grading.
     ****************************************************/
    

Without further ado

  1. Compare and contrast the four different versions (1.0, 1.1, 1.2 and 1.3) of the program DrawMeA shown on the Code tab.
  2. What differences, if any, do you notice when you compile and execute version 1.3 of DrawMeA using compilejava.net vs. compiling and executing the same code locally using javac and java? If you do notice any differences, what do you think might explain what you are observing?
  3. Use the javadoc utility (included in the JDK) to convert the source code for DrawMeA version 1.3 into a set of HTML files. Then open the file named index.html using a web browser and study it.

    Hint:

    > javadoc DrawMeA.java
  4. Using Windows Notepad, create a Java program that consists of a public class named PrintProgSays and a main method.
    1. Define the main method in terms of a parameter named args.
    2. When you compile and execute the program, the program should print another Java program.
    3. If, when you execute the program using the java interpreter, the first command line argument passed to PrintProgSays is the string Draw and the second argument is the string Sheep, then the program printed should be identical to DrawMeASheep version 1.0, except that your name should be listed in the @author field of the Javadoc comment instead of mine.
    4. If the first argument passed to the program is, say, Paint, and the second argument is, say, Dog, then PrintProgSays should print a program that is analogous to DrawMeASheep but with all occurrences of the string Draw replaced by Paint, all occurrences of the string Sheep replaced with the string Dog, and your name listed in the @author field of the Javadoc comment.
    5. Include Javadoc style comments with your program, using the programs and comments in this MESS as a guide. Provide end-of-line and multi-line comments as well if you feel they would make your program easier for someone else to understand.
  5. Test your program by redirecting the output to a file and then compiling and executing the file.
    1. To redirect the output of your program to a file using PowerShell and the java class loader, execute a command similar to the following after you have successfully compiled your program.
      java PrintProgSays Make Goat > MakeMeAGoat.java
    2. Verify that you created a valid Java program by compiling and executing the file you creating using PrintProgSays. Note that you may need to use javac’s -encoding option when you compile the new file as shown here:
      javac -encoding Unicode MakeMeAGoat.java
      java MakeMeAGoat
      Expected output:
      Make me a Goat!