Case study Students. Array of objects Arrays can hold objects (ref to objects!) Each cell in an array of objects is null by default Sample: from student.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
Phil Campbell London South Bank University Java 1 First Steps.
Copyright © Texas Education Agency, Computer Programming Class Basics.
C++ Classes & Data Abstraction
CS 106 Introduction to Computer Science I 02 / 18 / 2008 Instructor: Michael Eckmann.
Classes and Objects: Recap A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
1 More on Arrays Passing arrays to or from methods Arrays of objects Command line arguments Variable length parameter lists Two dimensional arrays Reading.
Arrays and Strings A way to make oodles of variables, and a deeper look at classes.
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Chapter 9 Introduction to Arrays
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Options for User Input Options for getting information from the user –Write event-driven code Con: requires a significant amount of new code to set-up.
Saravanan.G.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Hello AP Computer Science!. What are some of the things that you have used computers for?
1.  Collections are data structures that holds data in different ways for flexible operations  C# Collection classes are defined as part of the ◦ System.Collections.
Java Class Syntax CSIS 3701: Advanced Object Oriented Programming.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
Java Classes. Consider this simplistic class public class ProjInfo {ProjInfo() {System.out.println("This program computes factorial of number"); System.out.println("passed.
CSC1401 Classes - 1. Learning Goals Computing concepts Identifying objects and classes Declaring a class Declaring fields Default field values.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Mixing Static and Non-static
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
ACM/JETT Workshop - August 4-5, : Defining Classes in Java.
JAVA PROGRAMMING PART III. METHOD STATEMENT Form of method statement [ ] [static] ( [ ]) { } Example public static void main(String args[])
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Recitation 8 User Defined Classes Part 2. Class vs. Instance methods Compare the Math and String class methods that we have used: – Math.pow(2,3); – str.charAt(4);
1 COS 260 DAY 14 Tony Gauvin. 2 Agenda Questions? 6 th Mini quiz graded  Oct 29 –Chapter 6 Assignment 4 will be posted later Today –First two problems.
Outline Class and Object-Oriented Programing –Encapsulation and inheritance Example –Commission Employee –Encapsulation and inheritance Strings and Formatting.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
int [] scores = new int [10];
Topics Instance variables, set and get methods Encapsulation
OOP Basics Classes & Methods (c) IDMS/SQL News
CMSC 150 ARRAYS CS 150: Fri 10 Feb Motivation  Consider a list of your contact addresses: String Zero = String.
Introduction to programming in java Lecture 22 Arrays – Part 2 and Assignment No. 3.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Arrays Chap. 9 Storing Collections of Values 1. Introductory Example Problem: Teachers need to be able to compute a variety of grading statistics for.
Chapter 1 Object Orientation: Objects and Classes.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Chapter 8 Arrays and the ArrayList Class Arrays of Objects.
3 Introduction to Classes and Objects.
9.1 Class (static) Variables and Methods
Examples of Classes & Objects
using System; namespace Demo01 { class Program
Yanal Alahmad Java Workshop Yanal Alahmad
USING ECLIPSE TO CREATE HELLO WORLD
March 29th Odds & Ends CS 239.
CSC 113 Tutorial QUIZ I.
Interfaces and Constructors
Classes & Objects: Examples
CSE 1020:Programming by Delegation
Building Java Programs
Assignment 7 User Defined Classes Part 2
int [] scores = new int [10];
class PrintOnetoTen { public static void main(String args[]) {
Introduction to Java Brief history of Java Sample Java Program
ITE “A” GROUP 2 ENCAPSULATION.
Presentation transcript:

Case study Students

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

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);

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….

Class 2 Class 3 UML: universal modeling language

Procedural decomposition When have multiple tasks that operate on the same set of data. Complex problem broken into parts.

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

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)

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

How are these two classes related? Give a specific example from the code.

TestScoresApp Main method public class TestScoresApp { public static void main(String[] args) { TestScoresModel model = new TestScoresModel(); new TestScoresView(model); }

We have called two constructors: 1. TestScoresModel model = new TestScoresModel(); From TestScoresModel……. public TestScoresModel(){ indexSelectedStudent = -1; studentCount = 0; students = new Student[10]; }

2. new TestScoresView(model); Constructor from TestScoresView class ……. public TestScoresView(TestScoresModel m){ model = m; run(); // runs main command loop! }

Looking at student data TestScoresView class – Line 7: TestScoresModel model

look at TestModel Add methods to TestScoreView