tailieunhanh - Lecture Introduction to programming with Java - Chapter 8: Software engineering

This chapter presents the following content: Coding-style conventions, helper methods, encapsulation (with instance variables and local variables), algorithmic design with OOP, top-down design, stubs, merging driver method into driven class, accessing instance variables without using this. | Coding-Style Conventions Helper Methods Encapsulation (with Instance Variables and Local Variables) Algorithmic Design with OOP Top-down Design Stubs Merging Driver Method into Driven Class Accessing Instance Variables Without Using this Chapter 8 – Software Engineering 1 /********************************************************* * * Dean & Dean * * This class acts as a driver for the Student class. *********************************************************/ public class StudentDriver { public static void main(String[] args) { Student s1; // first student Student s2; // second student s1 = new Student(); ("Adeeb"); ("Jarrah"); s2 = new Student("Chun", "HeeJoo"); (); } // end main } // end class StudentDriver Coding-Style Conventions 2 /********************************************************* * * Dean & Dean * * This class handles processing of a student's name. *********************************************************/ import ; public class Student { private String first = ""; // student's first name private String last = ""; // student's last name //******************************************************* public Student() { } // This constructor verifies that each passed-in name starts with // an uppercase letter and contains lowercase letters thereafter. public Student(String first, String last) { setFirst(first); setLast(last); } Coding-Style Conventions 3 //******************************************************* // This method verifies that first starts with an uppercase // letter and contains lowercase letters thereafter. public void setFirst(String first) { // [A-Z][a-z]* is a regular expression. // See API Pattern class. if (("[A-Z][a-z]*")) { = first; } else { (first + " is an invalid name.\n" + "Names must start with an uppercase letter and have" + " lowercase letters thereafter."); } } // end setFirst Coding-Style . | Coding-Style Conventions Helper Methods Encapsulation (with Instance Variables and Local Variables) Algorithmic Design with OOP Top-down Design Stubs Merging Driver Method into Driven Class Accessing Instance Variables Without Using this Chapter 8 – Software Engineering 1 /********************************************************* * * Dean & Dean * * This class acts as a driver for the Student class. *********************************************************/ public class StudentDriver { public static void main(String[] args) { Student s1; // first student Student s2; // second student s1 = new Student(); ("Adeeb"); ("Jarrah"); s2 = new Student("Chun", "HeeJoo"); (); } // end main } // end class StudentDriver Coding-Style Conventions 2 /********************************************************* * * Dean & Dean * * This class handles processing of a student's name. .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.