Download presentation
Presentation is loading. Please wait.
1
AP Computer Science Welcome
2
Learning Targets Understand classroom expectations
Be able to set up folders for class projects Be able to create a Java project and classes within the project Be able to write a class Understand and be able to use escape sequences to format output. Be able to write a program from Scratch in Java
3
Successful Behavior Behavior/Discipline Plan:
Students are expected to be safe, responsible and respectful. Students not following these expectations may expect: verbal warnings, removal from class pending conference, parent contact, or referral to administration.
4
To be successful in this course:
Stay focused and productive in the classroom Excellent attendance Let your projects, daily work, quizzes and tests display your best effort Feel free to talk with me about your projects, questions, etc.
5
Computer Lab Rules No gum in class
No food or drink in the lab (except water with a lid at approved locations) No headphones or music except on days selected by teacher Absolutely no off-task Internet usage ( , games, chat, etc – anything other than class related) Absolutely no off-task Computer usage (ask teacher permission to use equipment for anything other than class assignments) Do NOT download any software (games, utilities, music, etc.) Do NOT use any “chat” software No CELL PHONE use in class without permission of Mr. Smith.
6
Materials Needed Each student will need a Composition Book, spiral or a tabbed off section in your three-ring binder for notes and handouts. Bring a pen or pencil with you everyday
7
Computer Science at West
Robotics Programming (RobotC) (One Semester) VEX Robotics/Engineering Computer Science I and II (Pascal) (One semester each) AP Computer Science (Java) (One year) Prepares students for the ‘A’ level exam Advanced Computer Projects (One semester, can be taken repeatedly) Developing original software Robotics Projects VEX Robotics Challenge (Mainly first semester) Spring tech conference (Second Semester)/FTC/VEX If we make the finals. Introduction to Engineering Design Design process 2 D and 3D design by hand 3D design on computer (Inventor)
8
Class Overview: First Semester
Basic I/O Math in Java Decision construct For loop Java Docs and Strings While Do..while* Random Arrays of Primitives Midterm More Arrays Sorting Intro to Objects Inheritance Project More OOP ArrayList Class Intro to OSI Networking model Review and Final
9
Grading Policy Assignments Programs 10 points Quizzes: 25 points
Tests: 100 Points Projects: 20 to 100 points Final: 200 points or 20% of your grade, whichever is less. Grading Scale A .. 90%+ B – <90% C – <80% D – <70% F .. Below 60%
10
Time to Log-on User Name: Use the ‘ID Number ‘ from your schedule for your user name. Password: Use your student ID number, also on your schedule to the left of your name, with a ‘.’ after it for your password. You will be asked to change your password on the first time you log in.
11
Log in and Create Class Folder
Log onto the network Your log in number is on your student ID number Your password is your First Initial Last Initial Birthdate. Example Susie Kalahan 1/1/2002 sk112002 Jose Mahindra 10/15/2001 jm Open YourName Folder In to top left of the desktop Make a new folder called APJava Keep your APJava Folder open
12
Creating Shortcuts 2) Double Click on ‘APJava’ Folder
1) Double Click on SMITH_GREG-Shortcut
13
Drag and Drop into your ComputerScience1 Folder.
Drag and Drop Into Your APJava Folder Drop
14
Shortcut to Class Website
Click on ‘AP Computer Science’
15
Put Shortcut in your Folder
Drag and Drop
16
Syllabus At home print out the syllabus, have your parents sign it and turn it in.
17
Find the Class Website, Find your Strengths
Smithcsrobot.weebly.com Click on the Computer Science 1 Link Click on ‘Find Your Strengths’ When complete Turn in a Word Document that includes: Your Name Class Period Two + strengths Any questions you have at this point in time Anything that would help me teach you better.
18
Start a New Project (Folder)
Now Project… 2) ‘Choose’ Navigate to your APJava Folder
19
Navigate to APJava Select Folder
20
1) Name The Project. No Spaces
2) Click OK
21
Start with a capital letter.
Start a new ‘Class’ Start with a capital letter. 1) New Class
22
Double Click on the Class to edit
23
Delete info between the {} after the public class Welcome1
Fill in the Class Enter your name, brief description of the program, the date and version 1.0. Delete info between the {} after the public class Welcome1
24
Enter the following program in BlueJ.
First Program Enter the following program in BlueJ.
25
Compiling the Program Click Compile Check for errors.
26
Right click on the class.
Running the Program Right click on the class. Select void main() Click OK
27
Output Screen
28
Include your name in the file name
Turn in the .java file Rename the java file to YourNameWelcome1 and turn in to the turn in folder. Include your name in the file name
29
public class Welcome1 Begins the class definition of class Welcome1
Breaking down the code. Begins the class definition of class Welcome1 Every program must include the definition of at least one class. Class names begin with a capital letter The class name must match the file name (Welcome1.java) This is case sensitive The file must have a .java extension (BlueJ should do this for you.) Identifier rules //Series of characters (letters, numbers, digit, _, $ //Must not start with a number //Cannot be a reserved word (purple in editor) Must describe what it is storing! Java IS Case sensitive Get out your notes.
30
{ Same as BEGIN in Pascal
Marks the beginning of the main body of the class. Needs to match up with a } Indent between the {}
31
public static void main(String args[])
This is the starting point of every java application (Main body of the program) () after main indicate it is a method (Like a procedure) Java classes usually contain more than one method Exactly one of these methods must be called main and defined as above for the program to run. Methods perform tasks and return information. Kind of like functions void indicates that it will return nothing. String args[] is required for the main's definition. More details later.
32
System.out.println("Welcome to Java programming!");
System.out is the standard output object for showing info in the command window The stuff inside () are the arguments System.out.println(); Displays the arguments and returns to the next line Like writeln() in Pascal "Wel..." This is a String of characters, message or string literal.
33
Comments and Common Errors
When successfully compiled it creates a Class file for Welcome1 called Welcome1.class This file contains the byte codes that represent this application Some common errors "bad command or file name", "javac: command not found", ""'javac' is not recognized as an internal or external command, operable program or batch file" Try: The system's path environment was not set properly. Check java.sun.com/j2se/5.0/install.html “Public class ClassName must be defined in file called ClassName.java" Try: Checking that the file name exactly matches the class name.
34
Describe the following
Review // Mr. Smith // First Program // Today’s date public class Welcome1 { //main method begins execution of Java application public static void main(String [] args) { //The start of the method System.out.println("Welcome to Java programming!"); }//End of method main } //End of class Welcome1 Describe the following
35
More on System.out public class Welcome1 {
//main method begins execution of Java application public static void main(String [] args) { //The start of the method System.out.print("Welcome to "); //Stays on the same line System.out.println(“Java programming”); }//End of method main } //End of class Welcome1
36
Showing Multiple lines
public class Welcome1 { //main method begins execution of Java application public static void main(String [] args) { //The start of the method System.out.println(“Welcome \nto \nJava \nprogramming”); }//End of method main } //End of class Welcome1
37
Escape Sequences \ is an ‘escape’ character
Some Common Escape Sequences \n for new line \t horizontal tab \r Carriage return, but on the same line \\ used to print the \character \” Used to display “
38
Displaying Formatted Text (printf)
public class Welcome1 { public static void main(String [] args) { //The start of the method System.out.printf(“%s\n%s\n”,"Welcome “,” to Java programming!"); }//End of method main } //End of class Welcome1 System.out.printf(Format String, Comma separated data to display) Format String Can contain fixed text, escape sequences and format specifiers Format Specifiers: Begin with % %s is a place for a string.
39
System.out.printf( “format-string” [, arg1, arg2, … ] );
Composed of literals (String characters) and format specifiers (%d, %-,.2f) Arguments are required only if there are format specifiers in the format string. Format specifiers include: flags, width, precision, and conversion characters in the following sequence: % [flags] [width] [.precision] conversion-character ( square brackets denote optional parameters )
40
AP Java: What do you recall about…
System.out.println(); public static void main (String [] args) { } System.out.printf(“%s”, “Hello World”) \n (%n also) %d %f %s
41
Flags % [flags] [width] [.precision] conversion-character ( square brackets denote optional parameters ) Flags: - : left-justify ( default is to right-justify ) + : output a plus ( + ) or minus ( - ) sign for a numerical value 0 : forces numerical values to be zero-padded ( default is blank padding ) , : comma grouping separator (for numbers >= 1000) : space will display a minus sign if the number is negative or a space if it is positive
42
Width % [flags] [width] [.precision] conversion-character ( square brackets denote optional parameters ) Specifies the field width for outputting the argument and represents the minimum number of characters to be written to the output. Include space for expected commas and a decimal point in the determination of the width for numerical values.
43
Precision % [flags] [width] [.precision] conversion-character ( square brackets denote optional parameters ) Used to restrict the output depending on the conversion. It specifies the number of digits of precision when outputting floating-point values . Numbers are rounded to the specified precision.
44
Common Conversion Characters
% [flags] [width] [.precision] conversion-character ( square brackets denote optional parameters ) d : decimal integer [byte, short, int, long] f : floating-point number [float, double] c : character Capital C will uppercase the letter s : String Capital S will uppercase all the letters in the string n : newline Platform specific newline character- use %n instead of \n for greater compatibility
45
Examples % [flags] [width] [.precision] conversion-character ( square brackets denote optional parameters ) System.out.printf("Total is: $%,.2f%n", dblTotal); , ->Comma Separated .2 ->Two digits to the right of the decimal f -> Floating point notation (real value) n -> Returns to the next line dblTotal -> The variable whose value will be displayed System.out.printf("Total: %-10.2f: ", dblTotal); - -> Left justified 10 -> 10 Spaces for displaying the value .2 -> Two digits to the right of the decimal System.out.printf("% 4d", intValue); Space -> Will leave space if positive or a – if negative 4 -> At least four spaces for displaying the value d -> Showing an integer value.
46
More Examples: Controlling integer width with printf
The %3d specifier means a minimum width of three spaces, which, by default, will be right-justified printf("%3d", 0); printf("%3d", ); printf("%3d", -10); -10 printf("%3d", );
47
Left-justifying printf integer output
To left-justify integer output with printf, just add a minus sign (-) after the % symbol, like this: printf("%-3d", 0); printf("%-3d", ); printf("%-3d", -10); -10 printf("%-3d", );
48
The printf zero-fill option
To zero-fill your printf integer output, just add a zero (0) after the % symbol, like this: printf("%03d", 0); 000 printf("%03d", 1); 001 printf("%03d", ); printf("%03d", -10); -10 printf("%03d", );
49
printf integer formatting
As a summary of printf integer formatting, here’s a little collection of integer formatting examples. Several different options are shown, including a minimum width specification, left-justified, zero-filled, and also a plus sign for positive numbers. Description Code Result At least five wide printf("'%5d'", 10); ' 10' At least five-wide, left-justified printf("'%-5d'", 10); '10 ' At least five-wide, zero-filled printf("'%05d'", 10); '00010' At least five-wide, with a plus sign printf("'%+5d'", 10); ' +10' Five-wide, plus sign, left-justified printf("'%-+5d'", 10); '+10 '
50
printf - floating point numbers
Description Code Result Print one position after the decimal printf("'%.1f'", ); '10.3' Two positions after the decimal printf("'%.2f'", ); '10.35' Eight-wide, two positions after the decimal printf("'%8.2f'", ); ' 10.35' Eight-wide, four positions after the decimal printf("'%8.4f'", ); ' ' Eight-wide, two positions after the decimal, zero-filled printf("'%08.2f'", ); ' ' Eight-wide, two positions after the decimal, left-justified printf("'%-8.2f'", ); '10.35 ' Printing a much larger number with that same format printf("'%-8.2f'", ); ' '
51
printf string formatting
Description Code Result A simple string printf("'%s'", "Hello"); 'Hello' A string with a minimum length printf("'%10s'", "Hello"); ' Hello' Minimum length, left-justified printf("'%-10s'", "Hello"); 'Hello '
52
Quick Review Starting a project in BlueJ Parts of your program
Open BlueJ Select your workspace (Folder) Project->New Project Click on ‘Class’ to create a class Double click on icon to edit the code Parts of your program public class FormattedPrint { public static void main(String [] args) {//The start of the method System.out.printf("%s\n%s\n","Welcome "," to Java programming!"); }//End of method main } Time to get started.
53
Your first programs Poem/Song: (YourNamePoem-Song)
Create or modify a poem or song to display from your Java Program. You will need to incorporate at least one printf. Check: Using printf (YourNameCheck) No input Display information on the screen for a check with your generous donation to the West Salem Robotics Club. ASCII Art Using print, printf and println create a simple ASCII art image.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.