Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lab Manual
CPCS204
Data Structures 1
1436/1435H
Lab - 1
Learning Procedure
Laboratory 1:
Statement Purpose:
This lab will give you an overview of Java programming environment.
Activity Outcomes:
This lab teaches you the following topics:
Review of the main Java programming concepts.
Review of defining and handling classes ingredients.
Recall algorithm and pseudo-code approaches.
Instructor Note:
As pre-lab activity, review Ch1, from the book Data Structures with Java by
John R. Hubbard and also the relevant instructor’s slides.
Names I.D.
1. .……………..………………………………. ………………………………
2. ..…………………………………………….. ………………………………
3. .……………………………………………... ………………………………
4. .…………………………………………….. ..…………………………….
1) Stage J (Journey)
Java programming environment
Java programming language specification
o Syntax of Java programs
o Defines different constructs and their semantics
Java byte code: Intermediate representation for Java programs
Java compiler: Transform Java programs into Java byte code
Java interpreter: Read programs written in Java byte code and execute
them
Java virtual machine: Runtime system that provides various services to
running programs
Java programming environment: Set of libraries that provide services
such as GUI, data structures, etc.
Classes Review
2) Stage a1 (apply)
1. Different data type available in Java
//Defining object
public class SimpleJava
{
public static void main (String[] args)
{
GreeterA worldGreeter = new GreeterA();
System.out.println(worldGreeter.sayHello());
}
}
Example2:
//Defining a Class
public class GreeterB
{
public void sayHello()
{
String message = "Hello, University!";
System.out.println(message);
}
}
{return (3.14*radius*radius);}
public double perimeter( )
{
return (2*3.14*radius);
}
public void changeTheRadius(int r)
{
radius = r ; // or this.radius r, explicit
parameter
}
public void output( ) // that called the method
{
System.out.println("center: " + xcenter + "," + ycenter +
" radius: " + radius);
}
}
3) Stage v (verify)
Lab Activities:
Task 1:
Number the marked statements from 1 to 7, in the blanks at the right for the
following program fragment, to show the logical order in which they are
executed.
Hint:
Verify your answer by using a static variable as a counter, then use print
command with each statement to show the (counter value) numbering
result.
Task 2:
Based on the rules that you studied in the course lecture about expressing an
algorithm and a pseudo-code for a given problem.
1) Write program code that translates your solution for problems 1 and 2.
Problem 1:
Problem 2:
Task 5:
Based on the rules that you studied in the course lecture about expressing an
algorithm and a pseudo-code for a given problem.
Problem:
For given 3 digits, apply the below rule to check that all possible permutations*
of a 3-digit integer number comprising the given 3 digits are divisible by 3 or
not.
* For example, for given three digits (5, 4, and 8), all possible 3-digit integer
number permutations are (548, 584, 458, 485, 845, and 854). Based on the
rule, they are all indivisible by 3.
Rule:
If the sum of three given digits is divisible by 3, so that any 3-digit number
comprising the given 3 digits is also divisible by 3.
4) Stage a2 (assess)
Lab Work:
In each laboratory you are assessed on your work within lab session based on
your participation, discussions and achievement of lab activities. Thus, each lab
has a portion of the (LAB WORK MARK). Therefore, a checklist of each lab is
used to evaluate your work. This checklist accounts the following criteria: