Menu

Ics 141 Programming Objects Lab 1 Name Points 15 Points Earned Must Attempt Complete Lab L Q43872538

ICS 141. Programming with Objects. Lab 1. Your Name:_____________________________________________________________Points: 15 Points earned:

You must attempt to complete the lab during lab time. If youcannot, you may work on it outside and submit it by the beginningof the next class. But I will allow that only if you work on theproblem in the assigned lab time. You may work alone or in a groupof 2-3. Your score will depend on how far you are able to completethe work and the correctness of the work. Note: all the labs are tobe turned in with hard copies. Goals: To learn IntegratedDevelopment Environment (IDE) Eclipse and to review old materials.Software engineering is a practice and a process that achievesrepeatability and quality of software products. Object orientedsoftware development is one method that is widely used in softwareengineering. In object oriented software development, you developsoftware in stages. Roughly, you can identify them asdesign/analysis phase, implementation/coding phase, anddebugging/maintenance phase. • In the design/analysis phase, yougather system requirements and problem statement; develop somehigh-level design documentations using UML, such as class diagrams,sequence diagrams. • In the development/coding phase, you transferthe design concepts into the working code. • In thedebugging/maintenance phase, you make sure the program worksappropriately by removing errors. In the following, we will applythe object-oriented method to develop a simple java program thatconsists of classes. The problem statement: Write a multi-classdesktop application (two classes). Name the application class(driver) “TestDate.” Name the worker class “Date.” The Date classrepresents a day of a year. This class should have three instancevariables: day: int, month: String, and year: int. It should have aconstructor that initializes the above three instance variables,three accessors (getters) for the three instance variables, onemutator (setter) method for the month instance variable, and atoString() method that returns the values of the above threeinstance variables in a string. The design: After analysis, wedecide to use two classes to do the job. The two classes are theworker class and the application class. The worker class is problemspecific and the application class is generic. The applicationclass will take care of the setup overhead and manage the interfacewith users. Finally, the application class will create an instanceof the worker class, initialize it and run it. The relationshipbetween the worker class and the application class is anassociation relationship. We name the worker class “Date” and theapplication class “TestDate”. Using UML notation, we get thefollowing class diagram. Implementation/coding: Using the aboveclass diagram we transform the design concepts to the follow javacode. Step 1, use Eclipse to create the following java source code(some methods are not finished, you need to supply the detailsaccording to the requirements in the comment section of eachmethod). In Eclipse, you need to create a project first. All thesource codes are stored inside the project. Projects are in turnsaved in workspace. You should choose the option of saving sourcefiles separately from class files. Once you started Eclipse,display the perspective screen by doing the following: Click thebutton “window” on the menu bar | select Open Perspective | selectJava The perspective screen is where you can type in your Javasource codes. In Eclipse, you can create a new class either byclicking a green icon in the menu bar or by selecting “create newclass” from the menu. Create the first class “Date” with followingsource code typed in (make sure that you supply the missing code asrequired). /** This is a worker class. The name of the class isDate. */ public class Date { // data fields private int day;private String month; private int year; // methods // constructormethod. public Date(int aDay, String aMonth, int aYear) { day =aDay; month = aMonth; year = aYear; } public void setMonth(StringaMonth) { month = aMonth; } public int getDay() { return day; }public String getMonth() { return month; } public int getYear() {/* Supply the details of this method (4 pts). This method needs toreturn the value of Class variable year. */ } public StringtoString() { /* Supply the details of this method (4 pts). Thismethod needs to return a String with the following value (in thefollowing, the year, month, and day should be the actual value ofthe class variable): “This date object has the following data:year, month, day” */ } } Step 2, use Eclipse to create a new class“TestDate” /** This is an application class that create a newinstance of Worker class “Date”. It is a test driver. */ publicclass TestDate { /** The main method. This is a must for all Javaapplications. */ public static void main(String[] args) { DatefirstDate = new Date(1, “January”, 2001); Date secondDate = newDate(2, “February”, 2002); System.out.println(“The first object dayis “ + firstDate.getDay()); System.out.println(“The first objectmonth is “ + firstDate.getMonth()); System.out.println(“The firstobject year is “ + firstDate.getYear());System.out.println(firstDate.toString()); System.out.println();System.out.println(“The second object day is “ +secondDate.getDay()); System.out.println(“The second object monthis “ + secondDate.getMonth()); System.out.println(“The secondobject year is “ + secondDate.getYear());System.out.println(secondDate.toString()); System.out.println();firstDate.setMonth(“March”);System.out.println(firstDate.toString()); } } Step 3, compile andrun the program. Tips on how to capture an active window screen: a.you make a window active by click its title bar. b. hold Alt keyand hit the Print Screen key (PrtSc). The Print Screen key shouldbe in the top row of the keyboard, towards the right. If you wantto capture the entire screen, just press the Print Screen key. c.Open a Word document. Move the cursor to the place where you wantthe screen capture to be inserted. Press Ctrl+V (hold Ctrl key andhit V). Cut and paste the outputs from the console window ofEclipse in the space below (7 pts): Hand to your instructor thefollowing: 1) this document, with output data.

Expert Answer


Answer to ICS 141. Programming with Objects. Lab 1. Your Name: _____________________________________________________________ Point…

OR