1

toaststicksrifleΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 5 χρόνια και 3 μήνες)

222 εμφανίσεις

Lab Java Exercise

(if you are already a
J
ava expert give someone near you a helping hand)

1.

Create a
sub
folder

on your
J
: drive
in the folder for COMP1148
called
FirstJava

2.

Copy the Folder “New Students”
from the
T: Drive in MyComputer

You may end up with
t
he folders looking
something like this




3.

Now open NetBeans on the Start
menu (e.g.
Start | All Programs | Programming | Java | NetBeans

)


This shows the top left corner only.










4.

To open the
NewStudents

examples click on the third icon from the le
ft, or select
File |
Open Project...
and browse to its location

on your J Drive
. You can recognise NetBeans projects by the coffee cup icon


5.

Once you have opened the project, New Student should appear in the Projects tab (top left). Double click on it an
d then double click on “Source Packages”.
You should see something like this showing the Exercises P
ackage, double click on
Exercises

and it will show the class Welcome in this package and on
double clicking this you will finally get
the program
to the
right hand screen as shown

below (phew!):










HELP!


If you need help please ask your neighbour, a member of staff
or a
mentor

to give you a hand


摯潴⁳楴⁴桥 e⁦潲潲o⁴桡渠㈠浩湵 e猠
畮u扬攠瑯⁤漠獯be瑨t湧⸠周楳⁩猠s扯畴b
discovering

JAVA not being
an expert.

6.

To make the computer Compile this code
(
t
ranslate the words into language the machine understands
-
bytecode)
you need to

by right
-
click on Welcome in the
Projects tab (top left) and selecting
Compile
File
.

Alternatively you can just hit F9.

You should see some output appear in the bottom window.

7.

Now we need to make the computer Run this program to see what it does. Do this by right
-
clicking on Welcome in the Projects tab and selecting
Run File
.

Altern
atively you can just hit Shift+F6.


You should see the following message at the bottom window.








8.

We are now going to write our own program


Right click on Exercises and select New | Java Class... and then in the dialog, change the class name to
MyW
elcome
. You should see something like this.











A
s you can see, NetBeans has written a ‘skeleton’ Java application.


Now modify it so that it matches the code below. The finished program should be
EXACTLY as follows

( you can use your name of cours
e)
:


The machine you are sitting at is
much less intelligent than you.
This means every space,
CAPITAL
,

punctuation and
spelling must be exactly as is
written here or it can’t process it.
READ
& WRITE
with care.

9.

Follow steps 6 & 7 to compile and run the program and you should see this output window appear

( you will have a different path quoted for your first line)










10.

Follow steps 8

& 9 for a new program called Options (shown below) and make sure it

compiles and runs successfully

(by following 6 & 7)
.



























What does it do and why? Can you adapt it to make it say ‘See you later’ when you run it?


Experiment with further variations yourself. Try the alternative of running from th
e command line if that is what you are used to.


11.

Write a new program called AgeCheck as given below.






















When you run this a dialog box allows input from the user. Here is an example with the input 12 and the resulting output








Experiment further with changing the existing programs or writing new ones

or

explore the wonders of NetBeans



Note by clicking on the


獩s湳nI⁨ ve⁨楤摥渠瑨

畮業灯牴p湴⁰慲瑳映瑨攠
c潤o⁦潲 眮

乯瑥⁔桩猠 業e⁴桥 e⁩猠
獯浥瑨s湧⁩渠 桩猠h楮攠瑯i
摯⁷楴栠愠扥瑴e爠
楮ie牡c瑩潮⁷楴栠o桥
畳u爮