Anda di halaman 1dari 50

SIX WEEKS TRAINING REPORT (June-July, 2012) TITLE OF THE TRAINING (Core JAVA) Submitted by:Sandeep Singh Reg.no.

:-10901876 Prog. Name:-B.Tech-CSE

CSE/IT Dept. School of SCIENCE & ENGINEERING Lovely Professional University, Phagwara

DECLARATION

I hereby declare that I have completed my six weeks summer training at APPIN Tech and lab(name of the company) and Appin Technology 233-A,opp. GNDU,Amritsar (location of organization) from 01/june/2012(start date) to 15/july/2012(end date) under the guidance of Mr.Amandeep Singh sir (Name of Industry coordinator). I have worked with full dedication during these six weeks of training and my learning outcomes fulfill the requirements of training for the award of degree of BTECH(Relevant Degree ), Lovely Professional University, Phagwara.

(Signature of student)

Students name:- Charanbir Singh Registration no:- 10905650

Date: 07/08/2012

Acknowledgement

First of all I am very happy that LPU is editing such type of activities In its course that provides students a chance to unleash their talent by making newer and newer projects.and finally I am very thankful to my training tutor who assigned in me the desire of making more and more project.

Charanbir Singh REG.NO:-10905650

TRAINING INSTITUTE:- APPIN SECURITY GROUP

Appin Security Group is a global Information Security company focused on training, consulting and solutions. The company was formed as a merger of two entities, XIRS Ventures Inc based in Austin Texas incorporated in 2003 and XIRS Appin incubated inside IIT, Delhi India formed in 2004. Later the name XIRS was dropped from the company and the merged entity is known as Appin Technologies. From USA & India, the company has now expanded its operations to Europe, Africa and South East Asia as well. The company has gone through several mergers and acquisitions and has operated businesses under the trademarks 'Appin Knowledge Solutions', 'XIRS Appin', 'Appin Technologies', 'Appin Overseas', 'Appin Software Security' all of whom form a part of the current Appin Security Group.

CAREERS - APPIN SECURITY GROUP Appin Security Group is an industry leader in Information Security & Investigative solutions and training. Our focus is to attract and develop great talent. Are you ready to be challenged? Are you ready to achieve and be recognized? It's all here for you. Explore the possibilities and start your job by enrolling yourself training programs at 'Appin Technology Lab'. To join a program, please click 'IT & Security training' icon on left and chose the nearest center. Hiring at Appin Security Group is limited to students graduating from Appin's training centers running globally. If you feel you are a deserving candidate and are unable to join our courses for any reason, you can write to us at 'hr@appinonline.com'.

WORK CULTURE

We all know that making time for relaxation, reflectionvacation, is important. But, at Appin, we believe it is equally important to maintain a work environment that encourages...fun! Employees have fun

Last year, employees and their blood relatives from 17 locations participated in golf outings, cricket and more and more. Super Savings

Lots of us are watching our budgets these days, so bargains and discounts are always welcome. Appin's HR benefits offer a total of 27 different discount programs for employees, including everything from day care to pet insurance to new cars! Setting the Goal for the Future

Professionalism and Integrity. Employer of Choice. Accelerated Growth. Global Strength and Consistency. These are Appin's four strategic priorities.

Taking Time

Most employees need to accrue five years of service with their employer to get 18 days of Personal Time Off each year. Appin offers employees at least that many, and they don't need to wait for years! Diversity

Appin continues its efforts to encourage and promote diversity in the workplace. Our New Delhi, India based headquarters has employees of all 25 states of India and 7 different nationalities

REPUTATION REPAIR, NEGATIVE CONTENT REMOVAL AND ONLINE REPUTATION MANAGEMENT SERVICE

Appin security group has developed and created a highly effective and efficient means to removing unwanted content from the Internet. We use our strong commercial relationships with social media and complaints or ripoff website publishers to get the content removed. Through the negative content removal service, appin will contact the host web site and not only demand the immediate take down of the content, but will also explain to them the improper nature of the posting and the need for its immediate removal. We also demand and warn the offending sites that it may not, under any circumstances, repost, resubmit, or otherwise disseminate the offending information else threaten them with legal action. We will also co-ordinate with police and lawyers to threaten content writers and website publishers. We may also use offensive security technology to protect your online reputation. The Information-age Security Specialists

Every day when Appin-ites wake up, we strive to come up with new ways to make our clients feel more secured. Its our mission to secure what is important to you, and to better it with time. We offer Information Security, Ethical Hacking & Allied Technology training to students and help them build a career by taking our coursesranging from 6 weeks to 3 years. Having trained and mentored over 83000 students in classroom and distance learning training sessions; we are confident of doing justice with a students career. We also provide exclusive business opportunities to Individuals and Small Business to start afranchise in their area

focused on IT & Security training and solutions. Over 110 entrepreneurs have joined hands with us in 18 nations and 70 cities. Its true that we are still very short of the 33000 mark achieved by Subway but hope to get there soon. We offer investigative solutions to investigative and intelligence bodies with specialization in cyber investigation work. Over 530 organizations including countries governments and topnotch lawyers trust us with theirinvestigation related work. Last but not the least, Appin holds unique distinction of providingInformation security consulting & network security services to India's all 4 major airports and is also a security solutions provider to over 1300 Websites that are audited and monitored by Appin globally. We have served Microsoft, Intuit, Actis & Daikin; we promise to help you with your security needs with equal zeal and enthusiasm if you are 20 people company that selects us as their security partner. We will feel extremely privileged for same.

ii LOCATION :-

Amritsar Appin Technology Lab 233-A, Opp. GNDU Amritsar. phone no:-:1912436741

iii. Specialization of Work Culture in the training organization.:-CORE JAVA iv . About the External Guide.:-Amandeep singh sir

INTRODUCTION OF JAVA:-

Java programming language was originally developed by Sun Microsystems, which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems.s Java platform (Java 1.0 [J2SE]). The latest release of the Java Standard Edition is 7 (J2SE). With the advancement of Java and its wide spread popularity, multiple configurations were built to suite various types of platforms. Ex: J2EE for Enterprise Applications, J2ME for Mobile Applications. Sun Microsystems has renamed the new J2 versions as Java SE, Java EE and Java ME respectively. Java is guaranteed to be Write Once, Run Anywhere. FEATURES:

Object Oriented : In java everything is an Object. Java can be easily extended since it is based on the Object model.

Platform independent: Unlike many other programming languages including C and C+ + when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual Machine (JVM) on whichever platform it is being run.

Simple :Java is designed to be easy to learn. If you understand the basic concept of OOP java would be easy to master. Secure : With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.

Architectural- neutral :Java compiler generates an architecture-neutral object file format which makes the compiled code to be executable on many processors, with the presence Java runtime system.

Portable :being architectural neutral and having no implementation dependent aspects of the specification makes Java portable. Compiler and Java is written in ANSI C with a clean portability boundary which is a POSIX subset.

Robust :Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking.

Multi-threaded : With Java's multi-threaded feature it is possible to write programs that can do many tasks simultaneously. This design feature allows developers to construct smoothly running interactive applications.

Interpreted :Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and light weight process.

High Performance: With the use of Just-In-Time compilers Java enables high performance.

Distributed :Java is designed for the distributed environment of the internet.

Dynamic : Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry extensive amount of runtime information that can be used to verify and resolve accesses to objects on run-time.

Java Development Kit (JDK):A Java Development Kit (JDK) is a program development environment for writing Java applets and applications. It consists of a runtime environment that "sits on top" of the operating system layer as well as the tools and programming that developers need to compile, debug, and run applets and applications written in the Java language.

Java Runtime Environment (JRE):The Java Runtime Environment (JRE), also known as Java Runtime, is part of the Java Development Kit (JDK), a set of programming tools for developing Java applications. The Java Runtime Environment provides the minimum requirements for executing a Java application; it consists of the Java Virtual Machine (JVM), core classes, and supporting files.

JAVA VIRTUAL MACHINE(JVM):A Java virtual machine (JVM) is a virtual machine that can execute Java bytecode. It is the code execution component of the Java software platform. JVMs are available for many hardware and software platforms. The use of the same bytecode for all JVMs on all platforms allows Java to be described as a write once, run anywhere programming language, versus write once, compile anywhere, which describes cross-platform compiled languages. Thus, the JVM is a crucial component of the Java platform

Java program

Syntax:Class class _name { public static void main(string ar[]) { Here we write the statements } } A simple program code that would print the words Hello World. public class MyFirstJavaProgram { public static void main(String args[]) { System.out.println("Hello World"); } } Compilation and execution of the program. Please follow the steps written below: 1. First open notepad and write the code written above. 2. Then we Save the file as : MyFirstJavaProgram.java. 3. After that Open a command prompt window and go to the directory where you saved the class. Let us assume its C:\. 4. Type ' javac MyFirstJavaProgram.java ' and press enter to compile your code. If there are no errors in your code the command prompt will take you to the next line.( Assumption : The path variable is set). 5. Now type ' java MyFirstJavaProgram ' to run your program. 6. You will be able to see ' Hello World ' printed on the window.

Java is an Object Oriented Language. As a language that has the Object Oriented feature Java supports the following fundamental concepts:

Polymorphism Inheritance Encapsulation Abstraction Classes Objects Instance

Polymorphism Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. For e.g:-class employee { public static main( String args[] ) { Student studentObject = new Student(); Employee employeeObject = new Employee(); Person ref = studentObject; //Person ref. points to a // Student object // getName() method of Student class is called String temp= ref.getName(); System.out.println( temp );

ref = employeeObject; //Person ref. points to an // Employee object //getName() method of Employee class is called String temp = ref.getName(); System.out.println( temp ); }

Inheritance Inheritance can be defined as the process where one object acquires the properties of another. With the use of inheritance the information is made manageable in a hierarchical order. Simple inheritance: When a subclass is derived simply from it's parent class then this mechanism is known as simple inheritance. In case of simple inheritance there is only a sub class and it's parent class. It is also called single inheritance or one level inheritance.

class A { int x; int y; int get(int p, int q){ x=p; y=q; return(0); } void Show(){ System.out.println(x); } } class B extends A{ A a = new A(); a.get(5,6); class A { a.Show(); int x; } int y; void display(){ int get(int p, int q){ System.out.println("B"); x=p; y=q; return(0); } } } void Show(){ System.out.println(x); It is the enhancement of the concept of inheritance. When a subclass is derived from a derived class then this mechanism is known as the multilevel inheritance. The derived class is called the subclass or child class for it's parent class and this parent class works as the child class for it's just above ( parent ) class. Multilevel inheritance can go up to number of level. e.g. public static void main(String args[]){ any Multilevel Inheritance

} } class B extends A{ void Showb(){ System.out.println("B"); } } class C extends B{ void display(){ System.out.println("C"); } public static void main(String args[]){ A a = new A(); a.get(5,6); a.Show(); } } Abstraction Abstraction refers to the ability to make a class abstract in OOP. An abstract class is one that cannot be instantiated. All other functionality of the class still exists, and its fields, methods, and constructors are all accessed in the same manner. We just cannot create an instance of the abstract class. declaration. abstract class Figure { double dim1; double dim2; Figure(double a, double b) { dim1 = a; dim2 = b; } abstract double area();

} class Rectangle extends Figure { Rectangle(double a, double b) { super(a, b); } double area() { System.out.println("Inside Area for Rectangle."); return dim1 * dim2; } } class Triangle extends Figure { Triangle(double a, double b) { super(a, b); } double area() { System.out.println("Inside Area for Triangle."); return dim1 * dim2 / 2; } } class AbstractAreas { public static void main(String args[]) { Rectangle r = new Rectangle(9, 5); Triangle t = new Triangle(10, 8); Figure figref; figref = r; System.out.println("Area is " + figref.area()); figref = t; System.out.println("Area is " + figref.area()); } }

Encapsulation Encapsulation is one of the four fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction. Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding.

Now we will look into the concepts Classes and Objects.

Object - Objects have states and behaviors. Example: A dog has states-color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class.

Class - A class can be defined as a template/ blue print that describe the behaviors/states that object of its type support.

Objects in Java: Let us now look deep into what are objects. If we consider the real-world we can find many objects around us, Cars, Dogs, Humans etc. All these objects have a state and behavior. If we consider a dog then its state is . name, breed, color, and the behavior is . barking, wagging, running If you compare the software object with a real world object, they have very similar characteristics. Software objects also have a state and behavior. A software object's state is stored in fields and behavior is shown via methods. So in software development methods operate on the internal state of an object and the objectto-object communication is done via methods.

Classes in Java: A class is a blue print from which individual objects are created. A sample of a class is given below: public class Dog{ String breed; int age; String color; void barking(){ } void hungry(){ } void sleeping(){ } } A class can contain any of the following variable types.

Local variables . variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.

Instance variables . Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.

Class variables . Class variables are variables declared with in a class, outside any method, with the static keyword.

A class can have any number of methods to access the value of various kind of methods. In the above example, barking(), hungry() and sleeping() are variables.

Below mentioned are some of the important topics that need to be discussed when looking into classes of the Java Language.

Constructors: When discussing about classes one of the most important sub topic would be constructors. Every class has a constructor. If we do not explicitly write a constructor for a class the java compiler builds a default constructor for that class. Each time a new object is created at least one constructor will be invoked. The main rule of constructors is that they should have the same name as the class. A class can have more than one constructor. Example of a constructor is given below: class Puppy{ public puppy(){ } public puppy(String name){ // This constructor has one parameter, name. } }

Object: Example of creating an object is given below: Creating an object student w1=new student()//object created of class employee student w2=new student()//copy created w1=w2//assign one object to another

class Puppy{

public Puppy(String name){ // This constructor has one parameter, name. System.out.println("Passed Name is :" + name ); } public static void main(String []args){ // Following statement would create an object myPuppy Puppy myPuppy = new Puppy( "tommy" ); } }

Java Package: In simple it is a way of categorizing the classes and interfaces. When developing applications in Java, hundreds of classes and interfaces will be written, therefore categorizing these classes is a must as well as makes life much easier. Import statements: In java if a fully qualified name, which includes the package and the class name, is given then the compiler can easily locate the source code or classes. Import statement is a way of giving the proper location for the compiler to find that particular class. For example following line would ask compiler to load all the classes available in directory java_installation/java/io : import java.io.*;

Loop Control statements:Java has very flexible three looping mechanisms. You can use one of the following three loops:

while Loop do...while Loop for Loop

As of java 5 the enhanced for loop was introduced. This is mainly used for Arrays.

The while Loop: A while loop is a control structure that allows you to repeat a task a certain number of times. Syntax: The syntax of a while loop is: while(Boolean_expression) { //Statements }

The do...while Loop: A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time. Syntax: The syntax of a do...while loop is: do {

//Statements }while(Boolean_expression);

The for Loop: A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. A for loop is useful when you know how many times a task is to be repeated. Syntax: The syntax of a for loop is: for(initialization; Boolean_expression; update) { //Statements }

Enhanced for loop in Java: As of java 5 the enhanced for loop was introduced. This is mainly used for Arrays. Syntax: The syntax of enhanced for loop is: for(declaration : expression) { //Statements }

The break Keyword: The break keyword is used to stop the entire loop. The break keyword must be used inside any loop or a switch statement. The break keyword will stop the execution of the innermost loop and start executing the next line of code after the block.

The continue Keyword: The continue keyword can be used in any of the loop control structures. It causes the loop to immediately jump to the next iteration of the loop.

In a for loop, the continue keyword causes flow of control to immediately jump to the update statement. In a while loop or do/while loop, flow of control immediately jumps to the Boolean expression.

Syntax: The syntax of a continue is a single statement inside any loop: continue;

The if Statement: An if statement consists of a Boolean expression followed by one or more statements. Syntax: The syntax of an if statement is: if(Boolean_expression) {

//Statements will execute if the Boolean expression is true }

The if...else Statement: An if statement can be followed by an optional else statement, which executes when the Boolean expression is false. Syntax: The syntax of a if...else is: if(Boolean_expression){ //Executes when the Boolean expression is true }else{ //Executes when the Boolean expression is false }

The if...else if...else Statement: An if statement can be followed by an optional else if...else statement, which is very usefull to test various conditions using single if...else if statement. Syntax: The syntax of a if...else is: if(Boolean_expression 1){ //Executes when the Boolean expression 1 is true }else if(Boolean_expression 2){ //Executes when the Boolean expression 2 is true }else if(Boolean_expression 3){ //Executes when the Boolean expression 3 is true }else { //Executes when the one of the above condition is true. }

Nested if...else Statement: It is always legal to nest if-else statements. When using if , else if , else statements there are few points to keep in mind.

An if can have zero or one else's and it must come after any else if's. An if can have zero to many else if's and they must come before the else. Once an else if succeeds, none of he remaining else if's or else's will be tested.

Syntax: The syntax for a nested if...else is as follows: if(Boolean_expression 1){ //Executes when the Boolean expression 1 is true if(Boolean_expression 2){ //Executes when the Boolean expression 2 is true } }

The switch Statement: A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case. Syntax: The syntax of enhanced for loop is: switch(expression){ case value : //Statements break; //optional case value : //Statements break; //optional

//You can have any number of case statements. default : //Optional //Statements }

Reason for choosing this training. Easy to Use: The fundamentals of Java came from a programming language calledc + + . A l t h o u g h powerful language, it was felt to be too complex in its syntax and inadequate for all of Java's requirements. Java built on, and improved the ideas of +,to provide a programming language that was powerful and simple to use. c+

Reliability:

Java needed to reduce the likelihood of fatal errors from programmer mistakes.With this in mind, object-oriented programming was introduced. Once data andits manipulation were packaged together in one place, it increased Javas robustness.

Secure:

As Java was originally targeting mobile devices that would be exchangingdata over networks, it was built to include a high level of security. Java is probably themost secure programming language to date.

Platform Independent:

Programs needed to work regardless of the machine theywere being executed on. Java was written to be a portable language that doesn't care aboutthe operating system or the hardware of the computer.

Project
Simulator of an Elevator Source code: //Elevator Simulator //An Elevator simulator program demonstrating 2 elevators in a four floor building. //No internal java activex component is used in this simulator. //Command Buttons are designed from scratch. //Class Elevator : Main Class holding paint method and mouse events. //Class MyButton : Used to design command buttons for user interface //Class Lift : Used to design 2 elevator

import java.awt.*; import java.awt.event.*; import java.applet.*; import java.io.*; import java.security.*;

//Main Elevator class

public class elevator extends Applet implements MouseListener, MouseMotionListener { String Msg=""; String UserId=""; String Trans=""; int opt,s1,t1,s2,t2; int mousex = 0, mousey = 0; // coordinates of mouse //First elevator user interface up command buttons //MyButton E11Up=new MyButton(); MyButton E12Up=new MyButton(); MyButton E13Up=new MyButton(); MyButton E14Up=new MyButton(); //MyButton E21Up=new MyButton(); //Second elevator user interface up command buttons MyButton E22Up=new MyButton(); MyButton E23Up=new MyButton(); MyButton E24Up=new MyButton(); //First elevator user interface down command buttons

MyButton E11Down=new MyButton(); MyButton E12Down=new MyButton(); MyButton E13Down=new MyButton(); //MyButton E14Down=new MyButton(); //Second elevator user interface down command buttons MyButton E21Down=new MyButton(); MyButton E22Down=new MyButton(); MyButton E23Down=new MyButton(); //MyButton E24Down=new MyButton();

//First elevator Internal control panel MyButton E11=new MyButton(); MyButton E12=new MyButton(); MyButton E13=new MyButton(); MyButton E14=new MyButton(); //Second elevator Internal control panel MyButton E21=new MyButton(); MyButton E22=new MyButton(); MyButton E23=new MyButton(); MyButton E24=new MyButton(); //Two Elevators MyLift L1=new MyLift(); MyLift L2=new MyLift(); //Administrator Control panel for First elevator MyButton E1Source=new MyButton();

MyButton E1Target=new MyButton(); MyButton E1Go=new MyButton(); //Administrator Control panel for Second elevator MyButton E2Source=new MyButton(); MyButton E2Target=new MyButton(); MyButton E2Go=new MyButton(); MyButton EStop=new MyButton(); MyButton E1Emergency=new MyButton(); MyButton E1Open=new MyButton(); MyButton E1Close=new MyButton(); MyButton E2Emergency=new MyButton(); MyButton E2Open=new MyButton(); MyButton E2Close=new MyButton();

public void init() { addMouseListener(this); addMouseMotionListener(this); opt=0; s1=1;t1=1;s2=1;t2=1; //used by administrator to keep record of elevators start and target position

//======================================================= ================================= //===============Defination Text,Id,Position and Size of different user command buttons //======================================================= =================================

E14Up.SetMyButton(300,50,30,22,"Up","E14Up"); //E14Down.SetMyButton(300,80,50,22,"Down","E14Down"); E13Up.SetMyButton(300,175,30,22,"Up","E13Up"); E13Down.SetMyButton(300,205,50,22,"Down","E13Down"); E12Up.SetMyButton(300,300,30,22,"Up","E12Up"); E12Down.SetMyButton(300,330,50,22,"Down","E12Down"); //E11Up.SetMyButton(300,425,30,22,"Up","E11Up"); E11Down.SetMyButton(300,455,50,22,"Down","E11Down"); E24Up.SetMyButton(500,50,30,22,"Up","E24Up"); //E24Down.SetMyButton(500,80,50,22,"Down","E24Down"); E23Up.SetMyButton(500,175,30,22,"Up","E23Up"); E23Down.SetMyButton(500,205,50,22,"Down","E23Down"); E22Up.SetMyButton(500,300,30,22,"Up","E22Up"); E22Down.SetMyButton(500,330,50,22,"Down","E22Down"); //E21Up.SetMyButton(500,425,30,22,"Up","E21Up"); E21Down.SetMyButton(500,455,50,22,"Down","E21Down"); E11.SetMyButton(50,530,8,8,"1","E11"); E12.SetMyButton(70,530,8,8,"2","E12"); E13.SetMyButton(90,530,8,8,"3","E13"); E14.SetMyButton(110,530,8,8,"4","E14"); E21.SetMyButton(690,530,8,8,"1","E21"); E22.SetMyButton(710,530,8,8,"2","E22"); E23.SetMyButton(730,530,8,8,"3","E23"); E24.SetMyButton(750,530,8,8,"4","E24");

//===========================Defination of Location,Size,Text,Id of Two Elevators L1.SetMyLift(1,200,50,80,"L1","L1"); L2.SetMyLift(1,600,50,80,"L2","L2");

//===========================Defination of Location,Size,Text and Id of Administartor Command Buttons E1Source.SetMyButton(20,601,50,20,"Source","E1Source"); E1Target.SetMyButton(20,622,50,20,"Target","E1Target"); E1Go.SetMyButton(100,610,30,20,"Go","E1Go"); E2Source.SetMyButton(670,601,50,20,"Source","E2Source"); E2Target.SetMyButton(670,622,50,20,"Target","E2Target"); E2Go.SetMyButton(770,610,30,20,"Go","E2Go"); EStop.SetMyButton(415,600,40,20,"Stop","EStop"); E1Emergency.SetMyButton(130,530,73,25,"Emergency","E1Emergency"); E1Open.SetMyButton(210,530,45,25,"Open","E1Open"); E1Close.SetMyButton(265,530,50,25,"Close","E1Close"); int k=370; E2Emergency.SetMyButton(k+130,530,73,25,"Emergency","E2Emergency"); E2Open.SetMyButton(k+210,530,45,25,"Open","E2Open"); E2Close.SetMyButton(k+265,530,50,25,"Close","E2Close"); }

//Main paint method starts //this method is used to draw applet window // different conditional checks are done here. public void paint(Graphics g) { EStop.Draw(g); E1Emergency.Draw(g); E1Open.Draw(g); E1Close.Draw(g); E2Emergency.Draw(g); E2Open.Draw(g);

E2Close.Draw(g);

g.setColor(Color.magenta); g.drawString("Administrator",400,590); g.setColor(Color.black); g.drawString("Internal Panel",500,560); g.drawString("Internal Panel",690,560); int i,j; g.setColor(Color.gray); for(j=150;j<=575;j=j+125) { g.drawLine(0,j-1,800,j-1); g.drawString("Floor No " + (5-(j /125)),380,j-130); } g.drawLine(0,575,800,575); g.setColor(Color.red); g.drawString("Elevator 1",180,20); g.drawString("Elevator 2",580,20); E14Up.Draw(g); //E14Down.Draw(g); E13Up.Draw(g); E13Down.Draw(g); E12Up.Draw(g); E12Down.Draw(g); //E11Up.Draw(g);

E11Down.Draw(g); E24Up.Draw(g); //E24Down.Draw(g); E23Up.Draw(g); E23Down.Draw(g); E22Up.Draw(g); E22Down.Draw(g); //E21Up.Draw(g); E21Down.Draw(g); E11.Draw(g);E12.Draw(g);E13.Draw(g);E14.Draw(g); E21.Draw(g);E22.Draw(g);E23.Draw(g);E24.Draw(g); L1.Draw(g); L2.Draw(g); g.setColor(Color.blue); /*g.drawString("Busy",100,40); g.drawString("Busy",100,190); g.drawString("Busy",100,340); g.drawString("Busy",100,490); g.drawString("Busy",660,40); g.drawString("Busy",660,190); g.drawString("Busy",660,340); g.drawString("Busy",660,490); */ UserId="User"; if(Msg=="E11") { L1.Move(g,1,UserId); } if(Msg=="E12") { L1.Move(g,2,UserId); }

if(Msg=="E13") { L1.Move(g,3,UserId); } if(Msg=="E14") { L1.Move(g,4,UserId); } if(Msg=="E21") { L2.Move(g,1,UserId); } if(Msg=="E22") { L2.Move(g,2,UserId); } if(Msg=="E23") { L2.Move(g,3,UserId); } if(Msg=="E24") { L2.Move(g,4,UserId); } if (Msg=="E11Up" && L1.Floor<1) { L1.Move(g,1,UserId);} if (Msg=="E12Up" && L1.Floor<2) { L1.Move(g,2,UserId);} if (Msg=="E13Up" && L1.Floor<3) { L1.Move(g,3,UserId);} if (Msg=="E14Up" && L1.Floor<4) { L1.Move(g,4,UserId);} if (Msg=="E11Down" && L1.Floor>1) { L1.Move(g,1,UserId);} if (Msg=="E12Down" && L1.Floor>2) { L1.Move(g,2,UserId);} if (Msg=="E13Down" && L1.Floor>3) { L1.Move(g,3,UserId);} if (Msg=="E14Down" && L1.Floor>4) { L1.Move(g,4,UserId);} if (Msg=="E21Up" && L2.Floor<1) { L2.Move(g,1,UserId);} if (Msg=="E22Up" && L2.Floor<2) { L2.Move(g,2,UserId);} if (Msg=="E23Up" && L2.Floor<3) { L2.Move(g,3,UserId);} if (Msg=="E24Up" && L2.Floor<4) { L2.Move(g,4,UserId);} if (Msg=="E21Down" && L2.Floor>1) { L2.Move(g,1,UserId);} if (Msg=="E22Down" && L2.Floor>2) { L2.Move(g,2,UserId);} if (Msg=="E23Down" && L2.Floor>3) { L2.Move(g,3,UserId);} if (Msg=="E24Down" && L2.Floor>4) { L2.Move(g,4,UserId);} UserId="Administrator"; if (Msg=="E1Source") { s1=s1+1; if(s1>4){s1=1;} } if (Msg=="E1Target") { t1=t1+1; if(t1>4){t1=1;} } if (Msg=="E1Go") { L1.Move(g,s1,UserId);L1.Move(g,t1,UserId);}

if (Msg=="E2Source") { s2=s2+1; if(s2>4){s2=1;} } if (Msg=="E2Target") { t2=t2+1; if(t2>4){t2=1;} } if (Msg=="E2Go") { L2.Move(g,s2,UserId);L2.Move(g,t2,UserId);}

g.setColor(Color.gray); for(j=150;j<=575;j=j+125) { g.drawLine(0,j-1,800,j-1); g.drawString("Floor No " + (5-(j /125)),380,j-130); } g.setColor(Color.blue); g.drawString(" At Floor " +L1.Floor,100,40); g.drawString(" At Floor " +L1.Floor,100,165); g.drawString(" At Floor " +L1.Floor,100,290); g.drawString(" At Floor " +L1.Floor,100,415); g.drawString(" At Floor" +L2.Floor,660,40); g.drawString(" At Floor" +L2.Floor,660,165); g.drawString(" At Floor" +L2.Floor,660,290); g.drawString(" At Floor" +L2.Floor,660,415); E1Source.Draw(g);g.setColor(Color.red);g.drawString(""+s1,80,615); E1Target.Draw(g);g.setColor(Color.red);g.drawString(""+t1,80,635); E1Go.Draw(g); E2Source.Draw(g);g.setColor(Color.red);g.drawString(""+s2,750,615); E2Target.Draw(g);g.setColor(Color.red);g.drawString(""+t2,750,635); E2Go.Draw(g); MakeHistory.WriteIt(MyLift.Trans,g);

// Handled mouse clicked.and Id is stored in Msg. Msg used in paint to identy command button clicked public void mouseClicked(MouseEvent me) { mousex=me.getX(); mousey=me.getY(); Msg=""; //Msg=E11Up.Execute(mousex,mousey) Msg=E12Up.Execute(mousex,mousey); if(Msg=="") Msg=E13Up.Execute(mousex,mousey); if (Msg=="") Msg=E14Up.Execute(mousex,mousey); if (Msg=="") Msg=E11Down.Execute(mousex,mousey); if (Msg=="") Msg=E12Down.Execute(mousex,mousey); if (Msg=="") Msg=E13Down.Execute(mousex,mousey); if (Msg=="") //Msg=E14Down.Execute(mousex,mousey); //Msg=E21Up.Execute(mousex,mousey) Msg=E22Up.Execute(mousex,mousey);

if (Msg=="") Msg=E23Up.Execute(mousex,mousey); if (Msg=="") Msg=E24Up.Execute(mousex,mousey); if (Msg=="") Msg=E21Down.Execute(mousex,mousey); if (Msg=="") Msg=E22Down.Execute(mousex,mousey); if (Msg=="") Msg=E23Down.Execute(mousex,mousey); if (Msg=="") //Msg=E24Down.Execute(mousex,mousey); Msg=E11.Execute(mousex,mousey); if (Msg=="") Msg=E12.Execute(mousex,mousey); if (Msg=="") Msg=E13.Execute(mousex,mousey); if (Msg=="") Msg=E14.Execute(mousex,mousey); if (Msg=="") Msg=E21.Execute(mousex,mousey);

if (Msg=="") Msg=E22.Execute(mousex,mousey); if (Msg=="") Msg=E23.Execute(mousex,mousey); if (Msg=="") Msg=E24.Execute(mousex,mousey); if (Msg=="") Msg=E1Source.Execute(mousex,mousey); if (Msg=="") Msg=E1Target.Execute(mousex,mousey); if (Msg=="") Msg=E1Go.Execute(mousex,mousey); if (Msg=="") Msg=E2Source.Execute(mousex,mousey); if (Msg=="") Msg=E2Target.Execute(mousex,mousey); if (Msg=="") Msg=E2Go.Execute(mousex,mousey); if (Msg=="") Msg=EStop.Execute(mousex,mousey);

//MyLift.MStatus=1;

//if(Msg=="EStop") // {MyLift.MStatus=0; return; } if (Msg!="") { repaint(); } //Msg=""; } //unhandled mouse events necessary to implements as // elevator class implements MouseListener, MouseMotionListener public void mouseEntered(MouseEvent me) { public void mouseExited(MouseEvent me) { } public void mousePressed(MouseEvent me) {} public void mouseReleased(MouseEvent me) {} public void mouseDragged(MouseEvent me) public void mouseMoved(MouseEvent me) { } } {} }

// Command Button coding starts class MyButton { int Left,Top,Width,Height; String Caption,Id; //used to set different attributes of a command button public void SetMyButton(int Left,int Top,int Width,int Height,String Caption,String Id) { this.Left=Left;

this.Top=Top; this.Width=Width; this.Height=Height; this.Caption=Caption; this.Id=Id; } //Used to draw command button on applet which uses graphics conted Gr of the Parent Applet public void Draw(Graphics Gr) { Gr.setColor(Color.blue); Gr.fillRoundRect(Left,Top,Width,Height,5,5); Gr.setColor(Color.gray); Gr.fillRoundRect(Left+3,Top+3,Width-6,Height-6,3,3); Gr.setColor(Color.black); Gr.drawString(Caption,Left+6,Top+16); } //Used to detect whether user clicked in command button // return "" if mouse is not within range // else returns id of command button which is stored in Msg String public String Execute(int x,int y) { if (x>=Left && x<=Left+Width && y>=Top && y<=Top+Height) return this.Id; else return ""; } }

// Coding of Lift(Elevator) starts class MyLift { public static String Trans="";

//public static int MStatus=1; int Left,Top,Width,Height; public int Floor; String Caption,Id; //different attributes of elevator are set by SetMyLift method public void SetMyLift(int Floor,int Left,int Width,int Height,String Caption,String Id) { this.Left=Left; this.Top=570-(Floor*125); this.Width=Width; this.Height=Height; this.Caption=Caption; this.Id=Id; this.Floor=Floor; } //used to draw elevator in parent applet //This method uses Graphics context(Gr) of Parent applet public void Draw(Graphics Gr) { Gr.setColor(Color.red); Gr.fillRoundRect(Left,Top,Width,Height,5,5); Gr.setColor(Color.gray); Gr.fillRoundRect(Left+3,Top+3,Width-6,Height-6,3,3); Gr.setColor(Color.black); Gr.drawString(Caption,Left+6,Top+16); } //Used to undraw elvator from the applet // It redraws Elevator in background color(White) on the parent applet public void Remove(Graphics Gr) { Gr.setColor(Color.white); Gr.fillRoundRect(Left,Top,Width,Height,5,5); Gr.fillRoundRect(Left+3,Top+3,Width-6,Height-6,3,3); Gr.drawString(Caption,Left+6,Top+16); }

//Used to move elevator from current floor to target floor //It also keeps record whether user/administrator moved the elevator public void Move(Graphics Gr,int TFloor,String UserId) { int TTop; TTop=570-(TFloor*125); int ydiff,dy; ydiff=TTop-Top; if (ydiff<0) { dy=-1;} else { dy=1;} ydiff=Math.abs(ydiff); int i,j,k; for(i=1;i<=ydiff;i++) { this.Remove(Gr); this.Top=this.Top+dy; this.Draw(Gr); for(j=1;j<=30000;j++) for(k=1;k<=50;k++); //if (MStatus==0) break; } Gr.setColor(Color.gray); Gr.fillRoundRect(300,625,275,20,5,5); Gr.setColor(Color.white); Gr.drawString(this.Id+" moved by " + UserId + " from "+this.Floor+ " to " + TFloor ,350,640); for(j=1;j<=30000;j++) for(k=1;k<=5000;k++); Trans=this.Id+" moved by " + UserId + " from "+this.Floor+ " to " + TFloor+"\n"; this.Floor=TFloor; }

} Learning Outcome from training:Introduction to Programming This unit is rather large and easily broken into two separate units Strands/Learning Outcomes 1A. Students will have an understanding of procedures relating to the classroom, use of compiler, and computer procedures. 1B. Students will have a basic familiarity with the layout of a driver program (main/begin) and how to run such a program Comments

This includes a Hello World program where students identify the code which controls screen output, and also looking at Chapter 1 of the Java MBCS 1Ba. Students will learn to use the BlueJ environment to This will be used as students create an instance of an object and test individual methods handle simple IO by passing parameters through blueJ to the methods and viewing the output as what is returned from the methods 1C. Students will use, write and Could also modify System.out.println() method calls introduce System.out.print() as well, and cover briefly string concatenation using the + operator 1D. Students will be able to identify the escape sequences \n, \t, etc. and determine output based on code that uses them 1E. Students will be able to recognize and write Use both // and /* */ notation comments to document their code 1F. Students will have an understanding of basic syntax rules as they apply to case sensitivity and the use of the ; throughout program 1G. Students will be able to declare variables of both This involves the use of new and primitive and object types. As a part of this students theconstructor call for should be able to: objects. (Random numbers?)

Recognize the primitive variable types

Identify the parts of creating an object (creating the reference variable and assigning it to the memory location created by the constructor call) 1H. Students should be able to use the variables they declared in a series of mathematical operations. As a part of this students will be able to:

Recognize the use of mathematical operators (except concatenation) must be used with primitive

variable types. Use the assignment operator to store the result of a calculation. 1I. Students should be able to use method calls to assign For Example: values to variables.

String name = new String(Tony); int len = name.length();

1J. Students should understand and be able to use primitive numeric type casting (int to double and vice versa) Program Assignments/Chapter Resources

Students should be reading API documentation and applying return values to assignments. int x = (int)4.5;

Input/Output Please note that this unit can either be treated as a separate unit or taught as part of a larger course. The primary focus here is not to teach students 1 method of input or output, but introduce a range of IO possibilities (some written by teacher) that will allow them to read object documentation and apply it to any situation. Strands/Learning Outcomes 2A. Students will have familiarity with basic concepts involved in sequential input. Comments Students will understand that when a series of values are entered into an input stream they are read from the stream in the same order in which they are entered.

2B. Students will be able to read the documentation for an object that will provide them with input or output and utilize that object accordingly. 2C. Students will be able to use the Integer and Double static Useful when input is given as a parse methods to convert Strings into numbers string and needs to be converted into a number. Possible IO packages include: Please note that these are not specifically recommended they are just examples of ObjectDraw (mouse input) Swing (JOption Pane, and using other preset forms possible IO packages that can

as the course progresses students will eventually be used for this unit. modify the frame code to create they layout of objects that they want)

Simple IO classes created by teacher to read from a file

Methods Strands/Learning Outcomes 3A. Students will be able to, given the outline of a data storage object, write simple methods that involve return statements with either just member data, a quick mathematical operation, or apply the IO principles covered already in the course. 3B. Students will be able to identify the difference between a regular method and a static method and how that applies to how the method is called. 3C. Students will know the rules of calling methods as they apply to calling a method from within the same object, as well as calling a method from an object reference. 3D. Students will be able to read inherited objects, recognizing the ability to call super class methods as if they were members of the same object. Comments Part II of case study

Using other static methods inside the main method similar to free functions in C++ (Also use of Color.red, etc. as static )

Decision Structures:

Strands/Learning Outcomes 4A. Students will be able to use boolean expressions to return a true or false value from a method. 4B. Students will be able to use if/then structures within methods to control the result of a method call. 4C. Students will be able to utilize boolean method calls

Comments Part III Case Study

within an if/then structure 4D. Students will be able to relational and logical operators to form complex boolean statements 4E. Students will be able to trace code containing boolean statements. 4F. Students will understand the creation and use of a class variable as a counter.

Looping Structures

Strands/Learning Outcomes 5A. Students will be able to recognize patterns in code that can be condensed into a repetition structure 5B. Students will be able to use a for structure to condense code that contains patterns. 5C. Students will understand the underlying structure of a collection class and be able to store values in a set. 5D. Students will be able to use a while structure to loop through an unknown number of iterations 5E. Students will be able to perform the following algorithms using either a set or an ArrayList and an iterator:

Comments Part IV of case study Adding a series of objects to a collection..

Place a series of values inside a collection Print a series of objects stored in a collection Perform a simple search of a series of objects in an Iterator Sort the items stored in an unordered collection (such as a set) and transfer the sorted group to a list Count objects with a specific attribute stored in a collection

Using an iterator (while(it.hasNext()) to retrieve values stored in a set. Many of these algorithms were done in procedural programs from a series of input values. The use of collection classes (and abstract IO classes) allows for the implementation of these algorithms with abstract collections (sets and lists).

Accumulate a total based upon an attribute of an object (ie. You have a collection of car dealerships from an area. Find the total number of cars sold within the area sum of cars sold at each individual dealer) 5F. Students will be able to use object casting when retrieving an object from a container

Introduction to Indexing/Array Lists

Strands/Learning Outcomes Comments 6A. Students will be able to iterate through an ArrayList using the .get() method with an index value. 6B. Students will be able perform the algorithms addressed in the previous chapter using indexing of a list as opposed to iterating through a collection. 6C. Students will be able to use ArrayLists whose subscripts are representative of an aspect of the data 6D. Students will understand the concept of object casting and the need for it when using container classes. Students will also be able to determine appropriate casting based on sub and super class relationships

AP I: More Algorithms for Collections Strands/Learning Outcomes AP1A. Students will be able to identify the three main interface collection classes specified by the subset and describe the individual properties of each. AP1B. Students will be able to identify and read documentation for the instance classes that implement the interfaces from CCA. AP1C. Students will be able to implement data structure changes to the MBS Case Study using the Collection Classes for environment implementations. AP1D. Students will have knowledge of abstraction and how it applies to interface and implementation classes as demonstrated through the collection classes. AP1E. Students will become familiar with different sort algorithms and the timing (Big-O) associated with each. Comments Set, Map, List

HashSet, TreeSet, HashMap,TreeMap, LinkedList

Case Study Part V

AP1F. Students will be able to trace and make generic statements about algorithms using a variety of data structures. AP1G. Students will be able to take an implementation of an algorithm andreimplement it using a different collection class, and discuss the ramifications in memory and timing associated with the changes.

Recursion

Strands/Learning Outcomes AP2A. Students will be able to identify a recursive method from code. AP2B. Students will be able to name the base case of a recursive method AP2C. Students will be able to trace recursive method calls and predict outcome of code based upon input values AP2D. Students will be able to use abstraction to make generalized statements about a recursive method without being given a specific starting value or series of values. s

Comments

Built in Arrays/2D Arrays

Strands/Learning Outcomes Comments AP3A. Students will be able to make comparisons between lists and built in 1 dimensional arrays AP3B. Students will be able to construct, fill, and manipulate 1 dimensional arrays of primitive values AP3C. Students will be able to construct, fill, and manipulate 1 dimensional arrays of objects, and recognize the impact of the null references for unconstructed objects that belong to that array AP3D. Students will be able to recreate the algorithms used in chapters 5 and 6 with iterators and ArrayLists for 1 dimensional arrays. AP3E. Students will be able to pass arrays to methods and

write methods with return values that are arrays AP3F. Students will be able to construct two dimensional arrays of primitives and objects AP3G. Students will be able to perform the following algorithms with two dimensional arrays:

Traverse the two dimensional array for the purpose of storing information. Print all elements of the array (or some property thereof) Traverse the array with a counter, counting elements with a specific attribute Traverse the array with an accumulator, performing a mathematical calculation based upon data stored in the two dimensional array Traverse the array and change the state of the items stored within it

Stacks and Queues

Strands/Learning Outcomes Comments AP4A. Students will understand the difference between the FIFO and LIFO data usage of stacks, queues and priority queues. structure AP4B. Students will apply the interface objects Stack, Queue, and Priority Queue as supplied by the CollegeBoard to various problem solving situations. AP4C. Students will be able to implement the Stack, Queue, and Priority Queue interface objects using either the collection classes or the List/Tree Node objects supplied by the CollegeBoard. AP5D. Students will be able to implement changes to the MBS Case Study using these data structures

List and Tree Implementations

Strands/Learning Outcomes AP5A. Students will be able to use (and trace code using) the ListNodeinterface supplied by the CollegeBoard to

Comments

implement a linked list data structure AP5B. Students will be able to implement the abstract Java List object usingListNode AP5C. Students will be able to create data storage objects that use ListNodesas member data AP5D. Students will be able to use (and trace code using) the TreeNodeinterface supplied by the CollegeBoard to implement a tree data structure AP5E. Students will be able to implement a version of the abstract Java List object using TreeNode AP5F. Students will be able to create data storage objects that use TreeNodesas member data

Object Oriented Design/Large Systems

Strands/Learning Outcomes Comments AP6A. Students will be able to dissect a problem statement into a series of interacting objects that are representative of the data storage and controllers needed to solve the problem. AP6B. Students will be able to write classes that implement the objects they describe from OODA. AP6C. Students will be able to create object maps based on existing programs as well as ones they design AP6D. Students will be able to write documentation of objects they design.