L03C: Assignment - Implementing the Displayable Interface
Assignment Objectives Practice on implementing a MVC projectImplement interfaces Deliverables A zipped Java project accordingto the How to submit Labs and Assignments. O.O. Requirements (theseitems will be part of your grade) One class, one file. Don't createmultiple classes in the same .java file Don't use static variablesand methods Encapsulation: make sure you protect your classvariables and provide access to them through get and set methodsall the classes are required to have a constructor that receivesall the attributes as parameters and update the attributesaccordingly Follow Horstmann's Java Language Coding GuidelinesOrganized in packages (MVC - Model - View Controller) ContentsImplement a Displayable interface. This new interface will help thegraphics implementation in the next assignment. app Creates model,view and controller objects Model private FootballPlayerDatafpData; • No parameter constructor • Methods FootballPlayerDataFootballPlayerData will now implement a second interface, calledDisplayable. public class Football PlayerData implements TableData,Displayable { The NetBeans Project This new assignment brings in anew interface, Displayable. Projects FilesA04C_Solution_FootballPlayer Source Packages Services app.javaController Controller.java Mo You should keep building from yourprevious TableMember/TableData Netbeans project. App.javaController Controller.java Model Displayable.javaFootballPlayer.java FootballPlayerData.java Height.java Model.javaPerson.java TableData.java TableMember.java View View.java Below isthe required initial code in app and in Controller. public classapp { public static void main(String[] args) { View view = newView(); Model model = new Model(); Controller controller = newController(view, model); } } The code for Controller.java DownloadController.java public class Controller { Model model; View view;public Controller(View v, Model m) { model = m; view = v;//============================================================================String sfltd, slltd, slbd, slth; //display using the default valuescreated by Model, and FootballPlayerData //These values should beset in the Constructor of FootballPlayerData //15 lines beingdisplayed with the first line being 0 sfltd = " " +this.model.getFpData().getFirstLineToDisplay(); slltd = " " +this.model.getFpData().getLastLineToDisplay(); slbd = " " +this.model.getFpData().getLinesBeingDisplayed(); slth = " " +this.model.getFpData().getLineToHighlight();this.view.basicDisplay("First Line = " + sfltd + ", Last Line = " +slltd + ", Lines Being Displayed = " + slbd + ", Line toHighlight=" + slth);//============================================================================//Sets news values and displays themthis.model.getFpData().setLinesBeingDisplayed(10);this.model.getFpData().setFirstLineToDisplay(100); sfltd = " " +this.model.getFpData().getFirstLineToDisplay(); slltd = " " +this.model.getFpData().getLastLineToDisplay(); slbd = " " +this.model.getFpData().getLinesBeingDisplayed(); slth = " " +this.model.getFpData().getLineToHighlight();this.view.basicDisplay("First Line = " + sfltd + ", Last Line = " +slltd + ", Lines Being Displayed = " + slbd + ", Line toHighlight=" + slth);//============================================================================//Sets news values and displays themthis.model.getFpData().setLinesBeingDisplayed(20);this.model.getFpData().setFirstLineToDisplay(10); sfltd = " " +this.model.getFpData().getFirstLineToDisplay(); slltd = " " +this.model.getFpData().getLastLineToDisplay(); slbd = " " +this.model.getFpData().getLinesBeingDisplayed(); slth = " " +this.model.getFpData().getLineToHighlight();this.view.basicDisplay("First Line = " + sfltd + ", Last Line = " +slltd + ", Lines Being Displayed = " + slbd + ", Line toHighlight=" + slth);//============================================================================//Sets news values and displays themthis.model.getFpData().setLinesBeingDisplayed(15);this.model.getFpData().setFirstLineToDisplay(-5); sfltd = " " +this.model.getFpData().getFirstLineToDisplay(); slltd = " " +this.model.getFpData().getLastLineToDisplay(); slbd = " " +this.model.getFpData().getLinesBeingDisplayed(); slth = " " +this.model.getFpData().getLineToHighlight();this.view.basicDisplay("First Line = " + sfltd + ", Last Line = " +slltd + ", Lines Being Displayed = " + slbd + ", Line toHighlight=" + slth);//============================================================================//Sets news values and displays themthis.model.getFpData().setLinesBeingDisplayed(12);this.model.getFpData().setFirstLineToDisplay(300); sfltd = " " +this.model.getFpData().getFirstLineToDisplay(); slltd = " " +this.model.getFpData().getLastLineToDisplay(); slbd = " " +this.model.getFpData().getLinesBeingDisplayed(); slth = " " +this.model.getFpData().getLineToHighlight();this.view.basicDisplay("First Line = " + sfltd + ", Last Line = " +slltd + ", Lines Being Displayed = " + slbd + ", Line toHighlight=" + slth); } } The code above will test youimplementation of the interface Displayable. If your implementationis correct it will generate the display below: First Line = 0, LastLine = 14, Lines Being Displayed = 15, Line to Highlight= 0 FirstLine = 100, Last Line = 109, Lines Being Displayed = 10, Line toHighlight= 0 First Line = 10, Last Line = 29, Lines Being Displayed= 20, Line to Highlight= 0 First Line = 0, Last Line = 14, LinesBeing Displayed = 15, Line to Highlight= 0 First Line = 112, LastLine = 123, Lines Being Displayed = 12, Line to Highlight= 0Functionality There is a new interface in this project, DisplayableDisplayable.java package Model; public interface Displayable {public int getFirstLineToDisplay(); public intgetLineToHighlight(); public int getLastLineToDisplay(); public intgetLinesBeingDisplayed(); public void setFirstLineToDisplay(intfirstLine); public void setLineToHighlight(int highlightedLine);public void setLastLineToDisplay(int lastLine); public voidsetLinesBeingDisplayed(int numberOfLines); } Displayable.java (makesure you read the FAQ below for more details) public intgetFirstLineToDisplay(); public void setFirstLineToDisplay(intfirstLine); these first two methods are about an int attribute thatwill hold the number of the first line to be displayed. The numberrepresents the index of an element in the array of the class thatimplements the TableData interface. public intgetLineToHighlight(); public void setLineToHighlight(inthighlightedLine); the two methods above are about an int attributethat will hold the number of the line on the screen that should behighlighted. It will be used only in a later assignment but it ispart of the interface and needs to be implemented even if it is notfully functional yet. public int getLastLineToDisplay(); publicvoid setLastLineToDisplay(int lastLine); these two methods areabout an int attribute that will hold the number of the last lineto be displayed. The number represents the index of an element inthe array of the class that implements the TableData interface.public int getLinesBeingDisplayed(); public voidsetLinesBeingDisplayed(int numberOfLines); these two methods areabout an int attribute that will hold the number of the lines thatwill appear on the screen at one time. It will be most likely 20but it should a variable. The application should work with anynumber of lines. So if this number is set to 10 or 15, this is thenumber of lines that should appear on the screen. FAQ - FrequentlyAsked Questions What are the initial (default) values for the 4 newvariables? firstLineToDisplay for testing purposes, it should beset to 0. This is the firs record in the ArrayList to be displayedon the first line on the screen. But any reasonable value is fine.We have 124 records in the ArrayList, so in principle any numberfrom 0 to 123 would work, although last line impose some limits.lastLineToDisplay Last line is dependent on the values of firstline and lines being displayed. linesBeingDisplayed This is thenumber of lines on the screen. It should be 15. lineToHighlight itwill not be used in this assignment and can be set to 0. Whathappens when invalid values (too small-negative or toolarge-outside the table size) are set to firstLineToDisplay?firstLineToDisplay when setFirstLineToDisplay receives a negativenumber firstLine needs to be set to 0 lastLine needs to berecalculated based on "0" and on the number of lines beingdisplayed linesBeingDisplayed when setFirstLineToDisplay receives anumber that is larger that the table size (the players ArrayListsize) - linesBeingDisplayed firstLine needs to be set to a numberthat leaves room to fit linesBeing displayed lastLine needs to berecalculated based on firstLine and on the number of lines beingdisplayed linesBeingDisplayed
L03C: Assignment - Implementing the Displayable Interface Assignment Objectives Practice on implementing a MVC project I
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am