DOC PREVIEW
Duke CPS 004 - Java 1

This preview shows page 1-2-23-24 out of 24 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CompSci 4Java 1 Nov 16, 2006Prof. Susan RodgerAnnouncements• Assignment 7 out• What we will do today– Compare Alice and Java– Learn a little Java– Experiment with JavaChap. 11 – What’s Next? Java• Java – object-oriented programming language– Classes, objects, inheritance– Control structures (if, while)– Functions, methods– Data types (integers, doubles, strings, arrays, lists)• Sound familiar?Some Data Types in Java•integer – Declare and initializeint value = 0; // variable is value– Update/modifyvalue = value + 2;• Real numbersdouble number = 4.5;number = number * 2.0; // multiply by 2• Careful with operationsvalue = 6/4; // what is value?String data type in Java• String is a class• Declare String variable and initializeString phrase = “”;phrase = “CompSci 4”;• Convert String to array of charactersphrase.toCharArray()• C o m p S c i 40 1 2 3 4 5 6 7 8char type in Java• char is for one character• Note char uses single quotes, string uses double quoteschar ch = ‘a’;if (ch == ‘a’){return “found match”;}else{return “no match”;}Some String member functions• String is a class, so has member functionsphrase = “CompSci 4”;• length() - returns number of characters in Stringint size = phrase.length();• toCharArray() – converts string to array of characters and returns the array• charAt(int position) – returns the character in an array at positionchar ch = phrase.charAt(2);Looping over a String• Collections loop – converts the String letters to a character array and iterates over the array with ch being one character from the array each time.for (char ch: letters.toCharArray()){// do something here}Conditionals – Format of “if”if ( condition){ // do if condition is true}else{// do if condition is false}Relational/Logic Operators• Relational operators < > <= >= == !=•Logic Operators – && (and)– || (or)– ! (not)if ((x > 0) && (y != 3)){ // do something}Problem 1 to Solve in Java• Bioinformatics– Area of computer science– Application of computational techniques to the management and analysis of biological information• Problem: Given a strand of DNA, determine the number of cytosine nucleotides presentProblem: Rewritten for CompSci• DNA is a string – array of characters– Only has letters c, t, a and g• Problem restated: how many c’s in a string?• Example: “catacgtatagtc”– Answer: 3 c’s• Write a method to return this number– See sheet for problem DNA-1What does code mean?• Name of class• Name of method in class• Return value (int is integer or number)• One parameter (type and name)Solve Problem on PaperHow We Will Solve Problems in Java• Write methods and test with testing interface:APT– Not a whole Java program, just a small part• Write a complete Java program– Not yet• Use a programming environment Eclipse to make it easier• Use submission tool AmbientEclipse (and Ambient)• See resources page on CompSci 4 web site to download Eclipse (and Ambient – built-into Eclipse)Solve this Problem• Write a method and test it on the APT– Type our solution into Eclipse– Load the file into APT and submitCreate a New Project in Eclipse• Start Eclipse• Select File -> New -> Project – Select Java Project and Next– Enter Project Name CPS4Sec1DNACreate a Class and Method• Click on project CPS4Sec1DNA– Select File -> New -> Class– Enter name DNAprofile– Select Finish– DNAprofile window appears – Cut and delete all the text from it so it is empty– Cut and paste starting code for problem– Complete the methodTesting a method using APT•Use APT to test method• All green means correct!• Class laptops – file is in C: workspaceSubmitting Java classwork for grade• In Eclipse, select “Ambient”, then “submit a project for grading”• Select “+” beside CPS 004• Then select date of classwork – classNov16• Then select today’s project to submit– CPS4SecXDNA• You will be prompted for your duke passwordSaving your work to your Duke Account• Check in your project by selecting “Ambient”, “Check in project”• First time only (Window -> preferences -> ambient -> checkin/checkout -> setup CVS)• Enter your Duke account password• If partner wants to save after one has saved, must click on project, select “Team”, then “disconnect”, then partner can try to saveTurn Alice code into Java Code• Select Edit Preferences• Must restart AliceClasswork today• Solve the two APTs on the CompSci 4 APT web page (create one Java project with two classes)– DNA-1 CGTA counting– DNA-2 CG counting• Submit work for grading (Ambient)– One submission for pair of partners– Include a README file in your project• Select “File” -> New -> File • enter name README.txt (both names in here)• Save files on Duke account – Ambient check in– FIRST TIME only (window -> preferences -> ambient -> checkin/checkout - setup CVS


View Full Document

Duke CPS 004 - Java 1

Documents in this Course
Lecture

Lecture

18 pages

Chapter 7

Chapter 7

18 pages

Chapter 9

Chapter 9

15 pages

Java 3

Java 3

11 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

28 pages

Chap 2

Chap 2

16 pages

Graphics

Graphics

20 pages

Lecture

Lecture

12 pages

HTML

HTML

16 pages

Java 1

Java 1

6 pages

Chapter 4

Chapter 4

16 pages

The Plan

The Plan

25 pages

Lecture

Lecture

16 pages

Chapter 6

Chapter 6

21 pages

Lecture

Lecture

18 pages

Lecture

Lecture

23 pages

Lecture

Lecture

16 pages

Lecture

Lecture

19 pages

Lecture

Lecture

12 pages

Lecture

Lecture

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

16 pages

Chapter 7

Chapter 7

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

4 pages

Lecture

Lecture

4 pages

Lecture

Lecture

8 pages

Lecture

Lecture

4 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

32 pages

Java

Java

4 pages

CompSci 4

CompSci 4

18 pages

Lecture

Lecture

26 pages

CompSci 4

CompSci 4

12 pages

HTML

HTML

17 pages

Lecture

Lecture

16 pages

Chapter 5

Chapter 5

22 pages

Lecture

Lecture

4 pages

Chapter 4

Chapter 4

10 pages

Chapter 2

Chapter 2

15 pages

Chapter 8

Chapter 8

14 pages

Lecture

Lecture

15 pages

Load more
Download Java 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Java 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Java 1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?