Topics include introduction to computers, programming languages, and Java; problem solving using object-oriented and algorithmic development methods; good programming practices and style; primitive data types; variables; arithmetic operations; assignment operations; relational and logical expressions; branching (if/else); loop control structures (while, for, do/while); multi-way branching (switch, break, continue); debugging strategies and tools; subprograms, object-based functions (methods), arrays, exception handling, files and streams.
Instructor Symon Chang has taught many Java classes in US, and published many Java articles on computer magazines in Taiwan.
class Test {
public static void main (String []args) {
System.out.println("Testing the Emergency Broadcast " +
"Program ");
}
}
If you install JDK 1.2 on Windows, read this page first. The size of JDK 1.2 is 20 MB. It will take 2+ hours to download under slow dial-up link.
If you are using your home machine, follow the instructions for that compiler/interpreter. You will need to create a text file called Test.java and put these contents in it:
class Test {
public static void main (String []args) {
System.out.println("Testing the Emergency Broadcast " +
"Program ");
}
}
Open a DOS window, and make sure you set the path:
SET PATH=c:\jdk1.1.7\bin;%path%Where the c:\jdk1.1.7 is the directory that you install your JDK under.
Then you should use the Java compiler (which is called javac) to compile it. Try this:
javac Test.javaIf everything is ok, you'll just get the prompt back. If there are errors in your code look at the error messages, fix the bugs, and try again. The result of a successful compilation is a .class file, so you should have Test.class in your directory now.
To run the program, you need to invoke the Java interpreter on the resulting class (which is called Test). So use:
java TestThis should cause the program to run and print the message on the terminal. Note that you do not put the name of the file that has the compiled class in it, you put the name of the class.
Note: If you want to know more in how to get start with Java, check here...
Note: If you have problem with classpath, check here...
while (true) // This is a do forever loop
{
if (amt == -1 ) System.exit(0);
// NOTE: this is the way to exit from the main program
}
To set-up your DOS windows for the Java class, you need to copy MS-DOS windows Icon from your desktop, and rename it to Java MS-DOS Window. Then, you need to change the properties of the Java Window. This will look like this....
The setjdk.bat file will look like this:
doskey SET PATH=c:\jdk1.1.7\bin;%path% SET CLASSPATH=.;c:\jdk1.1.7We have a news group now. Please check this web page , or visit GGU Page.
Check here for pre-quiz problem .
void setAmount(int amt) {}
int getChange() {}
int getQuarters() {}
int getDimes() {}
int getNickels() {}
int getPennies() {}
static int getCounts() { // get number of setAmount called by the main program
The Change class will store only three variables: Counts (Static), Amount
and Change.homework.java:7: Invalid method declaration; return type required.
public AccountNumber(int bal) { //constructor
^
A: You must use the same name of your class for constructor.
public int getCoins() {
// calculate how many coins for change
// for example: change of 31 will have 3 coins
}
public void displayChange() {
// display results
// for example:
/*
Your change of 69 cents is given as:
2 Quarters
1 Dime
1 Nickel
4 Pennies
*/
}
public String toString() {
// display object results
// for example:
/*
2 Quarters, 1 Dime, 1 Nickel, 4 Pennies
*/
return "Build your return string here!";
}
Note: If you think this main program is too difficult to do, then just write a main program to test all your method for now.
NOTE: See AwtField.java for how to enter text field.
class ReadingMaterials {
// Attributes: TYPE, type, title, counter
// Constructors
// Methods: toString(), setType(), getType(), setTitle(), getTitle(),
// getCounter()
}
public class Book extends ReadingMaterials {
// Attributes: TYPE, pages
// Constructors
// Methods: setPages(), getPages(), toString()
}
class TextBook extends Book {
// Attributes: TYPE
// Constructors
// Methods: toString()
}
class Novel extends Book {
// Attributes: TYPE, characters
// Constructors
// Methods: setCharacters(), getCharacters(), toString()
}
class Test {
static public void main(String[] arg) {
TextBook myBook = new TextBook("Java Software Solutions");
myBook.setPages(857);
Novel myNovel = new Novel("Adam of the Road", 317);
myNovel.setCharacters("Adam and Nick");
System.out.println("The first book is " + myBook.toString());
System.out.println("The second book is " + myNovel.toString());
}
}
D:\SYMON\ggu\cis101\sample>java Test The first book is Textbook: "Java Software Solutions," 857 pages The second book is Novel: "Adam of the Road," 317 pages, main characters are Adam and Nick
NOTE: The second midterm is on 02/23/99. Questions on the second midterm will be based on this homework assignment.
Also, the following two programs are important for the second midterm:
Animation of the Tai Chi Symbolic Sign. The sign rotates, zooms in and out on screen.
JUST FOR FUN - Here is a game: try to draw a picture without it being erased as you draw.
Simple java applet that responds to mouse events (draw lines) and uses a thread to perform some automation (chase cursor)