Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ICS 141. Programming with Objects. Lab 1. Your Name: Points: 15 Points earned: You must attempt to complete the lab during lab time. If you

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

ICS 141. Programming with Objects. Lab 1. Your Name: Points: 15 Points earned: You must attempt to complete the lab during lab time. If you cannot, you may work on it outside and submit it by the beginning of the next class. But I will allow that only if you work on the problem in the assigned lab time. You may work alone or in a group of 2-3. Your score will depend on how far you are able to complete the work and the correctness of the work. Note: all the labs are to be turned in with hard copies. Goals: To learn Integrated Development Environment (IDE) Eclipse and to review old materials. Software engineering is a practice and a process that achieves repeatability and quality of software products. Object oriented software development is one method that is widely used in software engineering. In object oriented software development, you develop software in stages. Roughly, you can identify them as design/analysis phase, implementation/coding phase, and debugging/maintenance phase. In the design/analysis phase, you gather system requirements and problem statement; develop some high-level design documentations using UML, such as class diagrams, sequence diagrams. In the development/coding phase, you transfer the design concepts into the working code. In the debugging/maintenance phase, you make sure the program works appropriately by removing errors. In the following, we will apply the object-oriented method to develop a simple java program that consists of classes. The problem statement: Write a multi-class desktop application (two classes). Name the application class (driver) "TestDate." Name the worker class Date." The Date class represents a day of a year. This class should have three instance variables: day: int, month: String, and year: int. It should have a constructor that initializes the above three instance variables, three accessors (getters) for the three instance variables, one mutator (setter) method for the month instance variable, and a toString() method that returns the values of the above three instance variables in a string. The design: After analysis, we decide to use two classes to do the job. The two classes are the worker class and the application class. The worker class is problem specific and the application class is generic. The application class will take care of the setup overhead and manage the interface with users. Finally, the application class will create an instance of the worker class, initialize it and run it. The relationship between the worker class and the application class is an association relationship. We name the worker class "Date" and the application class "TestDate". Using UML notation, we get the following class diagram. TestDate main() Date day: int month: String year: int Date() setMonth() getDay() getMonth() getYear() toString() Implementation/coding: Using the above class diagram we transform the design concepts to the follow java code. Step 1, use Eclipse to create the following java source code (some methods are not finished, you need to supply the details according to the requirements in the comment section of each method). In Eclipse, you need to create a project first. All the source codes are stored inside the project. Projects are in turn saved in workspace. You should choose the option of saving source files separately from class files. Once you started Eclipse, display the perspective screen by doing the following: Click the button "window" on the menu bar select Open Perspective select Java The perspective screen is where you can type in your Java source codes. In Eclipse, you can create a new class either by clicking a green icon in the menu bar or by selecting "create new class" from the menu. Create the first class "Date" with following source code typed in (make sure that you supply the missing code as required). This is a worker class. The name of the class is Date. public class Date ! // data fields private int day; private String month; private int year; // methods // constructor method. public Date(int Rax, String Menthint a less) { day = a Daxi month = Marth; year = axeasi public void set Month/String Menta) { month = amanth; public int getraxD { return day; public String getMontbl) { return month; public int get Year!) 1 /* Supply the details of this method (4 pts). This method needs to return the value of Class variable year. public String testsings) /* Supply the details of this method (4 pts). This method needs to return a String with the following value (in the following, the year, month, and day should be the actual value of the 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 new instance of Worker class "Date". It is a test driver. public class TestDate. /** The main method. This is a must for all Java applications. public static void main(String[] args) { Date firstdate = new Date(1, "January", 2001); Date secondDate = new Date 12, "February", 2002); Systementeerinti ("The first object day is + first. Retegst Rex(); Systementeerinti "The first object month is " + firstRatewget Month()); System antebrinth ("The first object year is " firstdatasetxeax()); Systsaeuteesintin (firstRatsutostring()); Systeme cutibsint (); Sxatamente brintin ("The second object day is " + Second Date getDax()); Sretane butelki ("The second object month is " + SecondRatarget Month(); System.out.printin ("The second object year is "_+ SecondDategetYear()); Systems autresinti (secendratantastsing()); Svatemoutprintin(); first Ratsuset Month ("March"); Systemet Bintah (firstRatsutostring()); Step 3, compile and run 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 key and hit the Print Screen key (PrtSc). The Print Screen key should be in the top row of the keyboard, towards the right. If you want to capture the entire screen, just press the Print Screen key. c. Open a Word document. Move the cursor to the place where you want the screen capture to be inserted. Press Ctrl X (hold Ctrl key and hit V). Cut and paste the outputs from the console window of Eclipse in the space below (7 pts)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions