Lecture 3 CSCI-260-W02. Class Agenda Last lecture review Homework practice New material Homework questions.

Презентация:



Advertisements
Похожие презентации
1 © Luxoft Training 2012 Inner and anonymous classes.
Advertisements

Sequences Sequences are patterns. Each pattern or number in a sequence is called a term. The number at the start is called the first term. The term-to-term.
A class is just a collection of variables--often of different types--combined with a set of related functions. The variables in the class are referred.
Purposes Working with students Working with teachers Opinion Conclusion.
Учимся писать Эссе. Opinion essays § 1- introduce the subject and state your opinion § 2-4 – or more paragraphs - first viewpoint supported by reasons/
Unit II Constructor Cont… Destructor Default constructor.
Inner Classes. 2 Simple Uses of Inner Classes Inner classes are classes defined within other classes The class that includes the inner class is called.
HPC Pipelining Parallelism is achieved by starting to execute one instruction before the previous one is finished. The simplest kind overlaps the execution.
Operator Overloading Customised behaviour of operators Chapter: 08 Lecture: 26 & 27 Date:
Ideal Family Were prepared by Iryna Molokova and Ilona Synytsia.
Ways to Check for Divisibility Vüsal Abbasov Dividing By 1 All numbers are divisible by 1.
2005 Pearson Education, Inc. All rights reserved. 1 Object-Oriented Programming: Interface.
Indirect Questions How do you make indirect questions? When do you use this grammar?
Describe a movie which made a strong impression on you. You should say: which movie it was – the name what the movie was about who the main stars were.
© 2009 Avaya Inc. All rights reserved.1 Chapter Two, Voic Pro Components Module Two – Actions, Variables & Conditions.
Yogesh Mehla Now concept of logic building is not so complex and not so simple. We will not work on how to make logic program in.
© Luxoft Training 2013 Using Reflection API in Java.
REFERENCE ELEMENTS 64. If your REFERENCE ELEMENTS toolbar is not in view and not hidden, you can retrieve it from the toolbars menu seen here. 65.
1/27 Chapter 9: Template Functions And Template Classes.
How to write a story First you have to….. Decide who the characters are. Who is going to be in the story? What sort of characters are they?
Транксрипт:

Lecture 3 CSCI-260-W02

Class Agenda Last lecture review Homework practice New material Homework questions

1.1 Review Questions What are main models of s/w life cycle? –How do they differ? –What are specific advantages of one against another? –Any other models you know? What are the goals quality s/w must satisfy? –HINT: There are 4 of them

Review Questions What types of programming do you know? –How do they differ? What are 2 ways to express structural design? Describe in your own words the ideas behind object-oriented methodology –List the terms you know and explain them

Review Questions What does UML stand for? What is its purpose? What kind of UML diagrams do you know? What are the different access control mechanisms in Java? How are they shown on UML class diagrams?

Homework Example

Specific Class Methods Constructor –An operation creating a new instance (object) of a class Observer (or accessor or getter) –An operation allowing to observe the state of an object without changing it Transformer (or mutator or setter) –An operation that changes the internal state of an object

UML Class Diagram for Date Class

Source Code of Date Class public class Date { protected int year; protected int month; protected int day; public static final int MINYEAR = 1583; // Constructor public Date(int newMonth, int newDay, int newYear) { month = newMonth; day = newDay; year = newYear; } // Observers public int getYear() { return year; } public int getMonth() { return month; } public int getDay() { return day; } public int lilian() { // Returns the Lilian Day Number // of this date. // Algorithm goes here. } public String toString() // Returns this date as a String. { return(month + "/" + day + "/" + year); }

About Lilian day The Julian day or Julian Day Number (JDN) is the integer number of days that have elapsed since an initial epoch defined as noon GMT January 1, 4713 BC in Julian calendar. This noon-to-noon day is counted as Julian day 0. –09/17/2014 2pm (ET), JDN is The Lilian day number (LDN) is similar to the Julian day number, except that LDN 1 started at midnight on the 1 st day of the Gregorian calendar, that is, October 15, 1582 –09/17/2014 2pm (ET), LDN is Conversion formula: –JDN – Other important day formats are in /** Returns the Lilian Day Number of this date. * Precondition: This is a valid date after 10/14/1582. * Computes # of days between 1/1/0 and this date as * if no calendar reforms took place, then subtracts * 578,100 so that October 15, 1582 is day 1. */ public int lilian() { /** number of calculated days from 1/1/0 to 10/14/1582*/ final int subDays = ; int numDays = 0; // Add days in years. numDays = year * 365; // Add days in the months. if (month <= 2) numDays = numDays + (month - 1) * 31; else numDays = numDays + ((month - 1) * 31) – ((4 * (month-1) + 27) / 10); // Add days in the days. numDays = numDays + day; // Take care of leap years. numDays = numDays + (year / 4) - (year / 100) + (year / 400); // Handle special case of leap year before leap day if (month < 3) { if ((year % 4) == 0) numDays = numDays - 1; if ((year % 100) == 0) numDays = numDays + 1; if ((year % 400) == 0) numDays = numDays - 1; } // Subtract extra days up to 10/14/1582. numDays = numDays - subDays; return numDays; }

Objects Date myDate = new Date(6, 24, 1951); Date yourDate = new Date(10, 11, 1953); Date ourDate = new Date(6, 15, 1985);

Applications An object-oriented application is a set of objects working together, by sending each other messages, to solve a problem. In object-oriented programming (OOP) a key step is identifying classes that can be used to help solve a problem. –An example: using our Date class to solve the problem of calculating the number of days between 2 dates (next 3 slides)

DaysBetween Design 1.Display instructions 2.Prompt for and read in info about the first date 3.Create the date1 object 4.Prompt for and read in info about the second date 5.Create the date2 object 6.IF dates entered are too early 6.1 Print an error message ELSE 6.2 Use the date.lilian() method to obtain the Lilian Day Numbers 6.3 Compute and 6.4 Print the number of days between the dates

// // DaysBetween.java by Dale/Joyce/Weems Chapter 1 // // Asks the user to enter two "modern" dates and then reports // the number of days between the two dates. // import java.util.Scanner; public class DaysBetween { public static void main(String[] args) { Scanner conIn = new Scanner(System.in); int day, month, year; System.out.println("Enter two 'modern' dates: month day year"); System.out.println("For example January 12, 1954 would be: "); System.out.println(); System.out.println("Modern dates occur after " + Date.MINYEAR + "."); System.out.println(); System.out.println("Enter the first date:"); month = conIn.nextInt(); day = conIn.nextInt(); year = conIn.nextInt(); Date date1 = new Date(month, day, year); Source Code of DaysBetween Class (Application)

System.out.println("Enter the second date:"); month = conIn.nextInt(); day = conIn.nextInt(); year = conIn.nextInt(); Date date2 = new Date(month, day, year); if ((date1.getYear() <= Date.MINYEAR) || (date2.getYear() <= Date.MINYEAR)) System.out.println("You entered a 'pre-modern' date."); else { System.out.println("The number of days between"); System.out.print(date1); System.out.print(" and "); System.out.print(date2); System.out.print(" is "); System.out.println(Math.abs(date1.lilian() - date2.lilian())); } Source Code of DaysBetween (Contd)

Homework Example

Todays Homework Exercise 29, 30 –Build on class modeling and inheritance TODO: –Recreate the classes as described –Add additional features from all listed exercises –Create the documentation as if you were writing these classes from scratch Build on existing textbook diagrams and descriptions –Create a test application that tests all functionality of both classes.