This lab will introduce you to Java classes, and take you through a simple process for developing them.
The Java compiler is named javac. It does not take a -o flag and output file name, since every class compiles into it its own .class file. To run, you invoke the Java virtual machine on a class containing a main method (note the lack of the .jave suffix in this step). Below are the commands to compile and run the demo files from the lab.
javac ClockTime.java TestClockTime.java Test.java java TestClockTime
To Do
Download the zip file containing all the files for this lab. Unlike some of our other labs, it is divided into multiple folders, one for each part of the lab. Begin with part 1, and continue on to the next part as you finish the ones before. You will be building your own class as you go, called Money.java. To complete each part you should have a program that compiles and runs, passing all tests. Each time you move on to a new part, you should copy your work from the previous folder into the next one. Here are some commands that may be useful:
- From your lab10 folder, move into the part1 folder: cd part1
- From your part1 folder, move into the lab10 folder: cd ..
- From your part2 folder, move into the part2 folder: cd ../part2
- From your lab10 folder, copy Money.java from the part1 folder to the part2 folder: cp part1/Money.java part2
- From your part1 folder, copy Money.java into the part2 folder: cp Money.java ../part2
- From your part2 folder, copy Money.java from the part1 folder into the part2 folder: cp ../part1/Money.java .
In case you get stuck, I am providing links to solution files for each of the parts of the lab: part 1, part 2 Try not to use these until you are done and checking your answers.