Class 1, Part 2 | Intro to Java 30-IT-396 |
In Class Demonstration
/**
*
* @author Brandan Jones
*/
public class CompletelyPointless {
// declarations and initializations
int someNumber = 1;
double someFraction = 2.345D;
char someChar = 'b';
/** Creates a new instance of CompletelyPointless
*/
public CompletelyPointless() {
}
// Run method calls the other methdods to do
work.
public void run(){
printInt();
printDouble();
printChar();
addAndPrint();
}
// print the int.
public void printInt() {
System.out.println("The
int is: " + someNumber);
}
// print the double.
public void printDouble() {
System.out.println("The
double is: " + someFraction);
}
// print the char.
public void printChar() {
System.out.println("The
char is: " + someChar);
}
// Do some math and print the results.
public void addAndPrint() {
int someAddedNumber
= someNumber + (int) someFraction;
double someAddedFraction
= someFraction + someNumber;
int someWeirdInt = someNumber
+ someChar;
System.out.println("someAddedNumber:
" + someAddedNumber);
System.out.println("someAddedFractoin:
" + someAddedFraction);
System.out.println("someWeirdInt:
" + someWeirdInt);
}
// Create an instance of CompletelyPointless,
call its run method.
public static void main(String args[]) {
CompletelyPointless
cp = new CompletelyPointless();
cp.run();
}
}
Created by: Brandan
Jones January 4, 2002