CS 145 Lecture 3

Agenda

  • String
  • Scanner
  • objects vs. primitives
  • methods vs. operators
  • a bunch of common String methods
  • KML

Code

StringFun.java

package lecture;

import java.util.Scanner;

public class StringFun {
  public static void main(String[] args) {
    char letter = 'a';
    String alphabet = "abcdefghijklmnopqrstuvwxyz";
    
    int sizeOfAlphabet = alphabet.length();
    System.out.println(sizeOfAlphabet);
        
    Scanner in = new Scanner(System.in);
    
//    System.out.println("Enter something, NOW: ");
//    String word = in.next();
//    System.out.println("The 1st character is: " + word.charAt(1));
    
    System.out.print("Enter your title: ");
    String title = in.next();
    String chopped = title.substring(0, 2);
    System.out.println(chopped);
    boolean isRich = chopped.equals("Dr");
    System.out.println("You are rich: " + isRich);
    
  }
}

Placemarker.java

package lecture;

import java.util.Scanner;

public class Placemarker {
  public static void main(String[] args) {

    Scanner in = new Scanner(System.in);
    
    System.out.print("Name: ");
    String name = in.next();
    System.out.print("Description: ");
    String description = in.next();
    System.out.print("Lon/lat: ");
    double lon = in.nextDouble();
    double lat = in.nextDouble();
    
    System.out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    System.out.println("<kml xmlns=\"http://www.opengis.net/kml/2.2\">");
    System.out.println("<Document>");
    System.out.println("<Style id=\"seethrough\"><PolyStyle><color>7fffffff</color></PolyStyle></Style>");
    System.out.println("<Placemark>");
    System.out.println("<name>" + name + "</name>");
    System.out.println("<description>This tree is surreal.</description>");
    System.out.println(" <Point>");
    System.out.println("<coordinates>-93.65057870772075,42.03081012742565</coordinates>");
    System.out.println("</Point>");
    System.out.println("</Placemark>");
    System.out.println("</Document>");
    System.out.println("</kml>");

  }
}

TODO

  • Work on preassignment 1
  • Read 1.4 in your book

Haiku

born 1990
was "20" until this year
now "201"

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *