Download presentation
Presentation is loading. Please wait.
1
Introduction to Programming using Java
Day 5 and 6 Review The “String” class Objects!
2
Review Variables Control If-then-else Loops Subroutines
The String class
3
Subroutine Review public class HelloWorld {
public static double calculateArea(int radius){ double x; System.out.println("inside calculateArea, radius: " + radius); x = 3.14 * radius * radius; return x; } public static void main(String[] args) { System.out.println("Hello World from Robot laptop"); double sheehyArea = calculateArea(6); System.out.println("my area was: " + sheehyArea); sheehyArea = calculateArea(10);
4
The String Class you can do operations on a String object!!
String myName = “Mr. Sheehy”; System.out.println( “length: “ + myName.length()); “uppercase: + myName.toUpperCase());
5
String Review public class HelloWorld {
public static void main(String[] args) { String myString = new String(“Hello world from Robot laptop”); System.out.println(myString); String myOtherString = “Hello world from Robot laptop”); System.out.println(myOtherString); }
6
The Java API
7
Task 1 declare and initialize a String object
initialize it to your full name using the java api get a new String that is a substring of your name the new String should be only your middlename
8
Demo outbound calling program
9
Objects an abstract notion. a way to encapsulate. classes objects
fields methods public and private
10
Task 2 create a class for some kind of animal
your class must have at least 2 data fields your class must have a constructor your class must have at least 2 methods in your main(), declare and initialize an object with your classes type make your object do something
11
Review for day 6 class layout classes versus objects revisit methods
return types how to declare a method
12
Day 6 new topics public and private class members
new advanced topic: inheritance you are almost ready!
13
Public and Private every member of a class is either public or private
you pick what to set it to based on what you want to expose to people who use the class encapsulation!
14
Inheritance a class may “extend” another class which means
the subclass has everything that the base class has the subclass IS the base class but not the other way around you can override how the base class acts
15
Task 3 using your object from last night
create another class that extends your class for example, if you have a Dog class, then your subclass could be Poodle make sure your subclass passes the IS-A test: a Poodle is a dog, but a dog isn't necessarily a Poodle add another method to your subclass to make your new class do something your base class can't do
16
Next Time review Robocode
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.