1 Page

mgp00007

Course: CGS 2414, Fall 2008
School: University of Florida
Rating:
 
 
 
 
 

Document Preview

what FtoC! With we know, lets analize a simple version of the FtoC algorithm in Java public class FtoC { public static void main(String[] args) { // initialize the value to convert double fahrenheit = 98.6; // the formula: C = F - 32 * 5 9 / double celsius = (fahrenheit - 32.0) * (5.0 / 9.0); // output message...

Register Now

Unformatted Document Excerpt

Coursehero >> Florida >> University of Florida >> CGS 2414

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.

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.
what FtoC! With we know, lets analize a simple version o...
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
FontsAWT provides the Font class for specifying the font type to useUse it along with Graphics' setFont() method Argument to the method must be a Font objectTo create the Font object, three arguments must be passed to the constructorFont name
University of Florida - CGS - 2414
Combining LabelsOmit the breaks to combine cases so they perform the same actionOutput of "Weekday" vs "Weekend": public static void main(String [] args) { int num = Integer.parseInt(args[0]); switch (num) {
University of Florida - CGS - 2414
Using Color ConstantsChaging colors with the defined constant colors import java.awt.*; import jpb.*; public class gtest { public static void main(String [] args) { DrawableFram
University of Florida - CGS - 2414
Array SubscriptingAllows selection of a specific element in an array / comment! 0 1 2 3 4 5 6 7 8 9 10 <- indices int[] channels = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13 }; System.out.println( channels[ 2 ] )
University of Florida - CGS - 2414
Arrays and Loops public class t1 { public static void main(String [] args) { int[] num_array = { 4, 10, 20 }; int i = 0;=> int sum = 0; while (i < num_array.length)
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) i *= 2; System.out.println( "i resul
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
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
A Closer LookTracing the StepsThe main program (in some other class) public static void main( String args ) { Account acct1 = new Account( 1000.0 ); acct1.deposit( 500.0 ); .The Account class (in the Account.j
University of Florida - CGS - 2414
CGS 2414Lecture 19ep@cise.ufl.edu
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>5a77ed934de79348d30e3e12d4d3d8e0393c652e.txt</Key><RequestId>930072FCA3FF7E28</RequestId><HostId>PRVXB62EkJ9CCSFZpxTVgszYGwq+
University of Florida - CGS - 2414
Final ClassesUse the keyword final to indicate that the class can not be extended public final class SavingsAccount extends Account { .In this case, SavingsAccount is not allowed to have subclassesMethods can also be decla
University of Florida - CGS - 2414
CGS 2414Lecture 27ep@cise.ufl.edu
University of Florida - CGS - 2414
CGS 2414Lecture 17ep@cise.ufl.edu
University of Florida - CGS - 2414
Garbage Collection (cont.)As a program runs, the garbage collector periodically checks for objects no longer referenced to and "deletes" themInitial acct1 object with balance of 1000.0 is no longer accessibleNo reference points to it, so it is d
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