This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: ASSIGNMENT 4 Classes and Objects COMP-202A, Fall 2010, All Sections Due: Friday, November 19, 2010 (23:55) You MUST do this assignment individually and, unless otherwise specified, you MUST follow all the general instructions and regulations for assignments. Graders have the discretion to deduct up to 10% of the value of this assignment for deviations from the general instructions and regulations. Part 1, Question 1: 0 points Part 1, Question 2: 0 points Part 2, Question 1: 45 points Part 2, Question 2: 55 points 100 points total Part 1 (0 points): Warm-up Do NOT submit this part, as it will not be graded. However, doing these exercises might help you to do the second part of the assignment, which will be graded. If you have difficulties with the questions of Part 1, then we suggest that you consult the TAs during their office hours; they can help you and work with you through the warm-up questions. Warm-up Question 1 (0 points) Create a file called CheckSubstring.java which contains a class called CheckSubstring . Inside this class, declare a public and static method called main() . This method should: • Ask the user to enter a line of text • Read a line of text from the keyboard • Ask the user to enter a second line of text • Read a second line of text from the keyboard • Display whether one of the lines of text read from the keyboard contains the other as a substring. If one of the lines of text indeed contains the other line as a substring, then the main() method should also display the smallest index in the containing line at which the other line occurs. Use the methods defined in the String class to determine whether a String is a substring of another String , and if so, the first position in the superstring at which the substring appears. Sample session: Enter a line of text: def Enter another line of text: abcdef "def" occurs in "abcdef" at position 3 "abcdef" is not a substring of "def" 1 Warm-up Question 2 (0 points) Write a class called Point ; each object which belongs to this class represents a point in two-dimensional space. Each point can be specified uniquely by two real numbers: its x-coordinate and its y-coordinate. Your Point class should provide the following public INSTANCE methods: • A constructor, which takes as parameters two values of type double ; these values represent the x and y coordinates of the newly-created Point , in this order. • An accessor method called getX() , which takes no parameters, and returns a value of type double that represents the x-coordinate of the target Point . • An accessor method called getY() , which takes no parameters, and returns a value of type double that represents the y-coordinate of the target Point ....
View Full Document
This note was uploaded on 02/22/2011 for the course COMP 202 taught by Professor Verbrugge during the Fall '07 term at McGill.
- Fall '07