Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Programming Assistant Professor Xiaozhong Liu

Similar presentations


Presentation on theme: "Web Programming Assistant Professor Xiaozhong Liu"— Presentation transcript:

1 Web Programming Assistant Professor Xiaozhong Liu http://scholarwiki.indiana.edu/S517/S517.html

2 Student… public class student { private String First_name; private String Last_name; private int ID; public String getName () { return First_name + " " + Last_name; } public int getSUID () { return SUID; } public student () { //Constructor! } Attributes or Fields Behaviors Constructor(s)

3 Student… public class student { private String First_name; private String Last_name; private int ID; public String major; } public class IUclass { public String class_name; private int ID; public student [ ] studs; } public class Application { public static void main(String[] args) { student stu1 = new student(); student stu2 = new student(); student [ ] studs = new student [2]; studs[0] = stu1; studs[1] = stu2; IUclass S517 = new IUclass(); S517.class_name = "Web Programming"; S517.studs = studs; }

4 Lab – Part I Design a laptop class. You will need to tell: 1.what is the attributes of the class?(at least, memory, hard drive size, type…) 2.what is the possible methods of the class? (at least, install application, uninstall application, update memory…) 3.design at least two constructors for this class 4. which attribute/method should be private/public? 5.create at least two instances from another class. * Do you need to design another class – Application?

5 Java Doc for class Example: http://docs.oracle.com/javase/6/docs/api/java/lang/String.html VERY IMPORTANT! To tell the class usage. What is the class properties? What is the functionality of each class method? Usage? You can create your Java Doc easily!

6 Javadoc for class Generate Javadoc for each class, attribute, or method Eclipse: source -> Generate Element Comment

7 Javadoc for class Generate class HTML map: Eclipse: Project -> Generate Javadoc

8 Lab – Part II Generate Javadoc for the laptop class you just defined: 1.Read the javadoc tutorial: http://students.cs.byu.edu/~cs240ta/fall2012/tutorials/javadoctut orial.html http://students.cs.byu.edu/~cs240ta/fall2012/tutorials/javadoctut orial.html 2.Generate comments for class, attribute, and method by using Eclipse 3.Generate Javadoc by using Eclipse, and open your class HTML by using browser.

9 Debug Break Point for debug… Debug As…

10 Debug Run your code line by line… Monitor variables in the memory Step into or Step Over

11 Debug Debug is important to tell the information flow between different objects. Help you to test your code! Help you to understand the code! Monitor the variable value change in the memory…

12 Lab 3: Debug Code Debug your code for Laptop-Application project. Set a break point in the main function. Monitor the information (variable) flow by using “step into”. Debug your Assignment 2 – step into one method, i.e., getVotes method, and monitor the variable value changes.

13 Static attribute/method public class student { private String First_name; private String Last_name; private int ID; public String major; static int number_of_students = 50000; static public int get_num_of_students () { return number_of_students; } number_of_students is instance independent!!!

14 Class, instance, properties… public class student { ID Name GPA required_credit min_GPA }

15 Class, instance, properties… public class student { ID Name GPA required_credit min_GPA } instance independent! public class student { public int ID; public String Name; public double GPA; public static int required_credit; public static double min_GPA; public double Calculate_GPA () { … } public static void print_min_GPA () { … }

16 Library Library is used to organize classes For instance: Java.util - miscellaneous utility classes Java.io – IO classes Java.sql – Database classes Import … if you want use some classes or a library…

17 Graduate Student… public class Graduate_student { private String First_name; private String Last_name; private int ID; private String Advisor; private String Research_area; public String getName () { return First_name + " " + Last_name; } public int getIUID () { return IUID; } public int getResearchArea () { return Research_area; }

18 Relationship between classes… Inheritance, Polymorphism

19 Relationship between classes… public class Undergrad_student extends student { private String Major; public String getMajor () { return Major; } public abstract class student { protected String First_name; protected String Last_name; protected int IUID; public String getName () { return First_name + " " + Last_name; } public int getIUID () { return IUID; } inheritance is a way to reuse code of existing objects, establish a subtype from an existing object, or both, depending upon programming language support.

20 Abstract class public abstract class SomeClass {... public abstract void SomeMethod(); } Some of the methods in a class can be declared abstract and left with only signatures defined A class with one or more abstract methods must be declared abstract

21 Super Class public class graduate_student extends student { String research; public graduate_student(String first_name, String last_name, int ID, String research) { super(first_name, last_name, ID); this.research = research; } public void print_student_info () { super.print_student_info(); System.out.println("Research Area: " + research); } Call some method from Super Class

22 Subclass Inherits attributes and methods of its superclass You can add new attributes and methods You can re-define (override) a method of the superclass You MUST provide its OWN constructors Does not have direct access to its superclass’s private attributes and methods

23 Relationship between classes… Manager Part_time Salesman Full_time Employee CEO

24

25 Lab 4: Class Relationship Design a list of classes for Library 1. Library resources (i.e., books and journals), which at least has name, publisher, author, and year information. 2. Books, with ISBN number, can be kept by users no more than 7 days. If overdue, user need to pay $0.5 per fay. 3. Journals, with with vol number, can be kept by users no more than 20 days. If overdue, user need to pay $0.1 per fay. 4. User. Each user can check out no more than 3 library resources. You need to design a method to calculate how much your need to pay when he/she return a resource.

26 Practice: Design a library system (object oriented design) 1.What is library resources? 2.What is library books? 3.What is library journals? 4.What is library digitalized journals? 5.How about library category?


Download ppt "Web Programming Assistant Professor Xiaozhong Liu"

Similar presentations


Ads by Google