Example code is in .txt instead of .java for display (PLEASE let me know if anything in example code looks scrambled or if you would like me to add an example of something!
SaysHello.javaDeitel & Deitel
Before You Begin section (right before Ch 1)
Read 1.4, 1.5, 1.7, 1.8, 1.9, 1.10
Skim rest of Ch 1
Getting NetBeans.
NetBeans Project
Now your project should be created and the SaysHello file should open.
☑ At the top of the SaysHello file, add a comment with all group member names (whenever you see an instruction like this while working independently, make up an imaginary second person's information to use).
☑ In your main (that is, between the curly braces of the main method) add the following code:
System.out.println("Hello World");Run the program using Run>Run File or Shift+F6. You should see Hello World printed out in the output below. (You should not need to explicitly compile first, NetBeans recompiles constantly).
☑ Changing the name of the project. Right click on the project name in the tree at the left and use Rename change the name of the project using today's classwork number and your userid or group number (e.g. cwk00jsmith or cwk01g02, whatever). Make sure to click the Rename project directory checkbox.
☑ Changing the name of a file. Right click on the SaysHello file in the tree at th
e left and use Refactor>Rename to change the name of the file to HelloWorld. Note that this changes the class name in the file as well -- the class name must match the name of the file.
☑ Adding new classes, and adding example code to your project. Right click on the package (just above the HelloWorld.java file) in the tree at the left and add a new Java class VariableExample. Go into this example code link: VariableExample.java and copy all the text. Replace the text of the new file you just created in the IDE.
Note that there is now an error in the first line, because my package name is different from yours. Netbeans puts a lightbulb in the margin of the code to show you where the problem is. Click on the lightbulb and you should see an option to Change the package declaration; clicking on it should fix the problem (you can also fix this simply by typing the correct name in the package statement.
Both HelloWorld and VariableExample have main methods, so both can run. To run the file you are looking at, make sure you use Run File, not just Run. Run VariableExample, which gives examples of creating variables, doing operations, and printing.
☑ The compiler marks a line with a red dot to indicate there is an error. Note that the error assumes your class name is right and your file name is wrong, but in our case it is the other way around. Fix the code so that it will work in the new file.
☑ In AboutMe, replace the statement that prints "Hello World" with separate statements that print greetings using the names of each member of your group (in any assignment with directions like this, if you are working independently, make up information for one imaginary person and use that in addition to your own).
☑ For one of these, use print instead of println, and use '\n' to put a linefeed at the end of the message.
☑ For one of these use print to print the message, then call println with no argument to add a newline after it.
Part C - Short Answer:
Answer these questions in a Word .docx document.
(Always turn in short answer questions in the same submission
as your project by attaching your Word document in
addition to your project zip file. Do not hide your short answers
inside your project zip unless told otherwise.) You should be able to see
the contents of your word document inside blackboard after you submit.
Always answer short answer questions in your own words, as if explaining to a peer.
[EC] (*EC means this part of the assignment is not required, it's a stretch goal if you're looking for something more interesting to try)
Java provides the printf method for formatted printing (covered in detail in the text). Add the following code to your main
System.out.printf("piece %.0f of %.5f pi %.9f %n", 3.141592653589793238, 3.141592653589793238, 3.141592653589793238);
and see what it prints. Based on this, add a line of code to AboutMe that uses printf to print:
For the low, low price of $99.44! (+$4.00 shipping and handling)
where the code uses the numbers 99.4411444 and 4. .
(hint: look veeery carefully at what I wrote in the previous line)
Part D - Turning In
☑ Go to where your project directory was saved by NetBeans. Right-click the folder icon and click Send To> Compressed (zipped) folder. A .zip file should be created.
In Blackboard, under Classwork, you will find an entry for this classwork (group links have a picture of people, assignment links have a picture of drawing tools). Click it. (If you ever see a blue Continue button at the right, click it and you should then see the submission page.)
☑ Attach your zip file and submit. Looking at your submitted assignment, you should see a link to download your project zip file.
☑ Click the link for your project and download it to your computer, then unzip it. Drag the unzipped directory to the editing area of Netbeans. Your project should open (this will probably mean you now have two copies of your project open).
Using this process you can always go back and get a copy of the work you submitted. It is your responsibility to check that you have turned in the correct project, correctly zipped, so I would strongly suggest downloading and checking your work every time you submit.