chapter8 - Chapter8SoftwareEngineering 1 2 1...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 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 2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 /********************************************************* * StudentDriver.java * * 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(); s1.setFirst("Adeeb"); s1.setLast("Jarrah"); s2 = new Student("Heejoo", "Chun"); s2.printFullName(); } // end main } // end class StudentDriver Coding-Style Conventions 3 2 1 4 5
Background image of page 2
3 /********************************************************* * Student.java * * This class handles processing of a student's name. *********************************************************/ import java.util.Scanner; 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 2 1 4
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 //******************************************************* // 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 (first.matches("[A-Z][a-z]*")) { this.first = first; } else { System.out.println(first + " is an invalid name.\n" + "Names must start with an uppercase letter and have" + " lowercase letters thereafter."); } } // end setFirst Coding-Style Conventions 3 2 1 4 5
Background image of page 4
5 // This method verifies that last starts with an uppercase // letter and contains lowercase letters thereafter. public void setLast(String last) { // [A-Z][a-z]* is a regular expression. See API Pattern class. if (last.matches("[A-Z][a-z]*")) { this.last = last; } else { System.out.println(last + " is an invalid name.\n" + "Names must start with an uppercase letter and have" + " lowercase letters thereafter."); } } // end setLast //******************************************************* // Print the student's first and last names. public void printFullName() { System.out.println(this.first + " " + this.last); } // end printFullName } // end class Student Coding-Style Conventions 3 2 1
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Read the notes. Coding-Style Conventions (hidden)
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/22/2010 for the course COMPSCI CS201 taught by Professor Sorenson during the Spring '10 term at Wisconsin Milwaukee.

Page1 / 25

chapter8 - Chapter8SoftwareEngineering 1 2 1...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online