Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more.
Course Hero has millions of course specific materials providing students with the best way to expand
their education.
Below is a small sample set of documents:
University of Florida - CGS - 2414
Following the loop public static void main(String [] args) { String input; while (true) { => SimpleIO.prompt("Enter a SSN: "); input = SimpleIO.readLine(); if (input.len
University of Florida - CGS - 2414
Parameters & Reference Types . Fraction f1 = new Fraction(1, 2); Fraction f2 = new Fraction(1, 4); Fraction f3 = f1.multiply( f2 );=> .In the Fraction class public Fraction multiply(Fraction other) {
University of Florida - CGS - 2414
Tracing the Loop public class loop { public static void main(String [] args) { int i = 1; int n = 10; while (i < n)=> { System.out.println( i + " " + i * i
University of Florida - CGS - 2414
Fixing Run-Time ErrorsWhen an exception occurs, your program exits abnormally and a message is displayedThe message includesType of exception - most exceptions are named based on the type of problemNumberFormatException - Illegal attempt to con
University of Florida - CGS - 2414
How it's DoneSuppose a program is executed as java myProg oh 2 be in PairsWhen myProg runs, each item following the program name is copied as a string into an array which we can access from main public class myProg { publi
University of Florida - CGS - 2414
Protected MembersHow to get around accessing private instance variables?Part deux:The protected access modifierGrants subclass access to a class' variables and methodsNifty access-modifier rulesprivate: Can be accessed only in the same clas
University of Florida - CGS - 2414
Following the loop public static void main(String [] args) { String input; while (true) { SimpleIO.prompt("Enter a SSN: ");=> input = SimpleIO.readLine(); if (input.len
University of Florida - CGS - 2414
Option 1Write the class from scratch (aka Code Replication Insanity!) public class SavingsAccount { private double balance; private double interest_rate; public SavingsAccount(double bal, double rate) {
University of Florida - CGS - 2414
Filled Rectangles import java.awt.*; import jpb.*; public class gtest { public static void main(String [] args) { DrawableFrame df; df = new DrawableFrame( "My Fram
University of Florida - CGS - 2414
A Closer LookTracing the StepsThe main program (in some other class) public static void main( String args ) {=> Account acct1 = new Account( 1000.0 ); / constructor is invoked acct1.deposit( 500.0 ); .The Accoun
University of Florida - CGS - 2414
Common Array OperationsCounting Occurrences public class acount { public static void main(String [] args) { int[] arr = { 4, 5, 12, 53, 12, 24, 14 }; int cnt = 0;=> for (int i = 0;
University of Florida - CGS - 2414
<?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>9d1c1e1a1417fc3a7efb918b605c1586af57bb80.txt</Key><RequestId>09A9877DD2F3549D</RequestId><HostId>vELkkcgGT6scENgT5K5H9kFMZqgE
University of Florida - CGS - 2414
toString Example (cont.)Shorten the code public class Time { / instance variables private int hour, min, sec; / constructor public Time(int h, int m, int s) { hour = h; min
University of Florida - CGS - 2414
About AWT ComponentsAll Java components are derived from the abstract superclass Component which provides state and behavior common to all AWT componentsPositionWhere the component is located on the screenSizeHeight & widthVisibilityWhether
University of Florida - CGS - 2414
Examples of AlgorithmsRecipeDirectionsSomewhere in Florida
University of Florida - CGS - 2414
Execution (cont.) public class eq { public static void main(String [] args) { String x = "abc"; String y = "cbs";=> if ( !x.equalsIgnoreCase(y) ) System.out.println("na
University of Florida - CGS - 2414
Filled ArcsSame as arcs, but filled to the origin import java.awt.*; import jpb.*; public class gtest { public static void main(String [] args) { DrawableFrame df;
University of Florida - CGS - 2414
Arrays as CountersOffsetsWhen counting values not starting at 0 (i.e.: 550 < n <= 560), use the minimum value as an offset to the subscriptExample:User enters 552 / 'num' now is 552 count[ num - 550 ]+;In this implementation, i
University of Florida - CGS - 2414
Arithmetic OperatorsBinary operators +Addition -Subtraction *Multiplication /Division %Remainder int i = 4; int j = i + 2; / j is assigned the value 6 i = j - 1; / i is reassigned the value 5 j = 12 %
University of Florida - CGS - 2414
Common Array OperationsCounting Occurrences public class acount { public static void main(String [] args) { int[] arr = { 4, 5, 12, 53, 12, 24, 14 }; int cnt = 0; for (int i = 0;
University of Florida - CGS - 2414
CGS 2414Lecture 3ep@cise.ufl.edu
University of Florida - CGS - 2414
Searching from the endTo do a search, starting from the end of the string, use the lastIndexOf() methodsAgain, searching for "or" but from the end / 0123456789012345678901234 - this is a comment! String str1 = "Albert
University of Florida - CGS - 2414
Drawable FrameTo use a graphics context (instance of the Graphics class) in Java, we need some sort of window"jpb" provides the DrawableFrame class - a simple window that can display a graphics context import java.awt.*; import j
University of Florida - CGS - 2414
Common Array OperationsCounting Occurrences public class acount { public static void main(String [] args) { int[] arr = { 4, 5, 12, 53, 12, 24, 14 }; int cnt = 0; for (int i = 0;
University of Florida - CGS - 2414
<?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>044ae27621d8d3cfc1c64d27118f2d8640802ad4.txt</Key><RequestId>1C80D4C0C7B80244</RequestId><HostId>RJuPjW2ANcyG09DA6F7xM/PNNfwU
University of Florida - CGS - 2414
Parameters & Primitive Types .=> int y, z; int x = 50; y = doSomething( x ); z = x; .Method definition: int doSomething(int y) { y += 30; return y; }
University of Florida - CGS - 2414
He said "private members"How to get around this?Account's constructor initializes balanceA subclass can invoke a superclass constructor by using the keyword super It must pass any arguments required by the superclass constructor public
University of Florida - CGS - 2414
Common Array OperationsCounting Occurrences public class acount { public static void main(String [] args) { int[] arr = { 4, 5, 12, 53, 12, 24, 14 }; int cnt = 0;=> for (int i = 0;
University of Florida - CGS - 2414
Filled Polygons import java.awt.*; import jpb.*; public class gtest { public static void main(String [] args) { DrawableFrame df; df = new DrawableFrame( "My Frame"
University of Florida - CGS - 2414
Other DataEverything in a computer is ultimately nothing more than just numbersNumbers are nothing more than a sequence of "bits"However, what the actual number represents is determined by the "type" of the dataIntegers - whole numbersFloating
University of Florida - CGS - 2414
Parameters & Primitive Types . int y, z; int x = 50; y = doSomething( x );=> z = x; .Method definition: int doSomething(int y) { y += 30; return y; }