Download presentation
Presentation is loading. Please wait.
Published byTyrone Cross Modified over 8 years ago
1
Case study Students
2
Array of objects Arrays can hold objects (ref to objects!) Each cell in an array of objects is null by default Sample: from student class
4
Let’s look at our constructors one more time!! this( ); public Student() { name = ""; test1 = 0; test2 = 0; test3 = 0; } //this one was featured in original code public Student (String nm, int t1, int t2, int t3) { name = nm; test1 = t1; test2 = t2; test3 = t3; } public Student (String nm, int t1, int t2, int t3) { name = nm; test = t1; test = t2; test = t3; } public Student () { this(““, 0, 0, 0); } public Student (Student s) { name = s.name; test1 = s.test1; test2 = s.test2; test3 = s.test3; } public Student (Student s) { this(s.name, s.test1, s.test2, s.test3); } Student m = new Student(“David”, 80, 85, 90); Student t = m; //t and m pointing to same object vs Student m = new Student(“David”, 80, 85, 90); Student t = new Student(m); Student student = new Student(“David”,0,0,0);
5
Modify Student class Store student grades in an array (not instance variables) Lets user maintain student information More complex tasks with multiple classes Along with this will come new functionalities that will require new methods….
7
Class 2 Class 3 UML: universal modeling language
9
Procedural decomposition When have multiple tasks that operate on the same set of data. Complex problem broken into parts.
10
TestScoresApp: this is the main application class – instantiates the view and the model! Manage student data – TestScoresModel class Methods include: size, currentStudent, replace, next, last…… – Student class Student constructors, etc….. View classes – TestScoresView / menu and user interactions
11
Let’s look at managing the data 1. Student class – blue print for student objects…remember. Name and 3 test scores as instance variables – Modified this: (look at new code)
12
2. TestScoresModel Let’s look at it….. Instance variables: Array of student objects Selected index - an int Current number of students – an int Methods…. See comments
13
How are these two classes related? Give a specific example from the code.
14
TestScoresApp Main method public class TestScoresApp { public static void main(String[] args) { TestScoresModel model = new TestScoresModel(); new TestScoresView(model); }
15
We have called two constructors: 1. TestScoresModel model = new TestScoresModel(); From TestScoresModel……. public TestScoresModel(){ indexSelectedStudent = -1; studentCount = 0; students = new Student[10]; }
16
2. new TestScoresView(model); Constructor from TestScoresView class ……. public TestScoresView(TestScoresModel m){ model = m; run(); // runs main command loop! }
17
Looking at student data TestScoresView class – Line 7: TestScoresModel model
18
look at TestModel Add methods to TestScoreView
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.