ReviewsofArraysofObjects

ReviewsofArraysofObjects - Arrays of Objects Arrays of...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Arrays of Objects
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Arrays of String Objects Command Line Arguments public static void main ( String [ ] args ) { }
Background image of page 2
The NameTag Class public class NameTag { public static void main (String [ ] args) { System.out.println (“ “ + args[0] ); System.out.println (“My name is “ + args[1] ); } }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Using command line arguments java NameTag Hi April args[0] is “Hi”, args[1] is “April” Hi My name is April java NameTag Greetings Ali Greetings My name is Ali
Background image of page 4
Checking if args are present Inside main: if (args.length != 2) { System.err.println (“ Greeting and “ + “ name required”); System.exit(1); }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Array-based List Use an array to manage a list of objects The array is filled from element 0 and the array is partially-filled (most of the time!) Operations on the list include add, remove, traverse Insert is an add operation that maintains some order to the list. Items may have to be shifted to make room at the appropriate slot
Background image of page 6
CDCollection Class Manages an array of objects Each object is an instance of the CD class
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CD class public class CD { private String title; private String artist;
Background image of page 8
CD class (continued) public CD (String name, String performer) { title = name; artist = performer; }
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CD class (continued) public String toString ( ) { return title + “ performed by “ + artist ; }
Background image of page 10
CDCollection class public class CDCollection { private CD [ ] collection; private int count;
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

ReviewsofArraysofObjects - Arrays of Objects Arrays of...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online