1 / 13

You should understand everything on this slide

You should understand everything on this slide. public class TestClass { public static void main(String[] args ) { System. out .println ( "public static void main(String[] args ) is where it all begins!" ); int myIntegerVariable = 77;

selma
Download Presentation

You should understand everything on this slide

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. You should understand everything on this slide publicclassTestClass { publicstaticvoid main(String[] args) { System.out.println("public static void main(String[] args) is where it all begins!"); intmyIntegerVariable = 77; System.out.println("I can have cool integer variables like " + myIntegerVariable); TestClassmyObject = newTestClass(); // I can also call functions like this myObject.myFunction("Test"); // ...but I haven't fully explained yet what the deal with "new" is // and how myObject is involved. } publicvoidmyFunction(String foo) { int[] arrayVariable = newint[25]; for(int i = 0; i < arrayVariable.length; i++) { System.out.println("Array Value at index " + i + " is " + arrayVariable[i]); } } }

  2. Classes and ObjectsArrayListsHashMapsHashSets When arrays are just not cool enough.

  3. In case you missed the email… • The Link is now staffed 5pm-11pm, Sunday-Thursday! Get help! • You first APT assignment is due tomorrow at 8am. How many folks are planning to be at the Link tonight? • Hangman (due next Wednesday 1/25 at 8am) is posted and ready to go. Many other things are coming due too! • Videos and notes will be linked off the syllabus

  4. In the Optional Textbook • Read chapters 1-3 (should be fast, but do some of the exercises at the end of Chapter 3) • The later part of this class will also deal with bits of chapter 16

  5. The Story Thus Far publicclassTestClass { publicstaticvoid main(String[] args) { System.out.println("public static void main(String[] args) is where it all begins!"); intmyIntegerVariable = 77; System.out.println("I can have cool integer variables like " + myIntegerVariable); TestClassmyObject = newTestClass(); // I can also call functions like this myObject.myFunction("Test"); // ...but I haven't fully explained yet what the deal with "new" is // and how myObject is involved. } publicvoidmyFunction(String foo) { int[] arrayVariable = newint[25]; for(int i = 0; i < arrayVariable.length; i++) { System.out.println("Array Value at index " + i + " is " + arrayVariable[i]); } } }

  6. Objects: they combine data and functions together Data: “cgga” Functions: setStrandData getStrandData mutate addBasePair Data: “gattac” Functions: setStrandData getStrandData mutate addBasePair

  7. addBasePair function DnaStrand strand = new DnaStrand(); strand.setStrandData(“cga”); //prints cga System.out.println(strand.getStrandData()); strand.addBasePair(“t”); //prints cgat System.out.println(strand.getStrandData());

  8. Why Objects? • See the coolness of java’s String class!

  9. BEWARE! Never compare 2 strings like this: String foo; String bar; //some other code if(foo == bar) { System.out.println(“Strings are equal!”) } Always compare them like this: if(foo.equals(bar)) { System.out.println(“Strings are equal!”) }

  10. is3rdBasePairCytosine DnaStrand strand = new DnaStrand(); strand.setStrandData(“tac”); if(strand.is3rdBasePairCytosine()); { System.out.println(“cytosine!”); } The function is3rdBasePairCytosine returns a boolean – a primitive type that is either true or false You might check out the String Javadoc for some useful functions

  11. 4 Classes You Will Get to Know is CompSci 100 • String • ArrayList – an expandable list you can add or remove elements from • HashSet – a list that prevents duplicate elements • HashMap – a “dictionary” where you can associate a particular key with a particular value

  12. getBaseCounts public HashMap<Character,Integer> getBaseCounts() { HashMap<Character,Integer> baseCounts = new HashMap<Character,Integer>(); baseCounts.put(‘c’, 0); baseCounts.put(‘g’, 0); baseCounts.put(‘a’, 0); baseCounts.put(‘t’, 0); for(inti = 0; i < myData.length(); i++) { char currentBase = myData.charAt(i); //your code goes here } return baseCounts; } When you’re finished, submit your code via ambient.

  13. What you should know • What the difference between class and objects is, and how objects work • 4 key java objects to help you with apts and homeworks: • String • ArrayList • HashMap • HashSet

More Related