Iti1120 Assignment 47

Presentation on theme: "VPL basic – data and variables Young Joon Kim MSRDS First Beginner Course – STEP6."— Presentation transcript:

1 VPL basic – data and variables Young Joon Kim MSRDS First Beginner Course – STEP6

2 2 Topics Procedure for VPL Programming Data and variable activities Defining variable Reading variable Displaying your name Input data Manipulate data with “Calculate”

3 3 VPL Visual Programming Language –Easy programming tool for novices and students Easy to start Easy to learn Easy to skill up –Draw logics –Provide intuitive and understandable flow –Applicable for most S/W development area

4 4 Procedure for VPL programming

5 5 Step1: Add activities or services Add activities Add services

6 6 Step2: Set values Procedure for VPL programming Set values

7 7 Step3: Connect each activity or service Procedure for VPL programming Connect

8 8 Step4: Connect functions Procedure for VPL programming

9 9 Step5: Connect data for each item Procedure for VPL programming

10 10 Procedure for VPL programming Step6: Save and run a diagram

11 11 Procedure for VPL programming Step7: Check the result

12 12 Procedure for VPL programming Check log data Log data

13 13 Procedure for VPL programming Stop VPL running

14 14 Data and variable activities

15 15 Data and variable activities Data activity –Define constant values –Can’t be modified Variable activity –Keep the values –Can be modified

16 16 Adding “Data” activity Double click “Data” activity or drag and drop Select data type Input data 1 2 3 Double-click Select data type Input default value

17 17 Double click “Variable” activity or drag and drop Adding “Variable” activity Double-click

18 18 Defining variable

19 19 Defining variable Click “…” icon Click icon

20 20 Add variable Change name Select variable type Defining variable Click Change name Click Select type Click 1 2 3

21 21 Assign value to the variable Defining variable Connect

22 22 Select “SetValue” item Defining variable

23 23 Defining variable Assigned value

24 24 Reading variable

25 25 Reading variable Use “Calculate” activity Double-click

26 26 Reading variable Connect “Variable” and “Calculate” activities Connect

27 27 Reading variable Select “state” item from the list

28 28 Reading variable Add “.” Select “a” item from the list Add “.” Select “a” 1 2

29 29 Reading variable Add a “Simple Dialog” service Double-click

30 30 Reading variable Connect “Calculate” and “Simple Dialog” service

31 31 Reading variable Select “AlertDialog” function

32 32 Reading variable Select “value” item from the left list

33 33 Reading variable Save and run diagram

34 34 Reading variable Execution result

35 35 Displaying your name

36 36 Displaying your name Prepare below diagrams

37 37 Displaying your name Connect “Data” and “Calculate” activities

38 38 Displaying your name Type below text in the “Calculate” box –“My name is “ + value

39 39 Displaying your name Connect “Calculate” and “Simple Dialog”

40 40 Displaying your name Select “AlertDialog” Select “value”

41 41 Displaying your name Save and run diagram

42 42 Displaying your name Execution result

43 43 Input data

44 44 Input data Add “Data” and set below text –“Input your name: “ Add a “HelloApps Console” service Double-click 1 2 3

45 45 Input data Connect “Data” and “Console” Select “Write” Select “value” 1 2 3

46 46 Input data Copy and paste “HelloAppsConsole” service Connect first “Console” and second “Console” service Select “ReadLine” function 2 3 1 Copy first Console service

47 47 Copy and paste “HelloAppsConsole” service Connect second “Console” and third “Console” service Select “WriteLine” function Input data 1 Copy first Console service 2 3 4

48 48 Input data Save and run diagram

49 49 Execution results Input data Type your name

50 50 Manipulate data with “Calculate”

51 51 Add “Calculate” activity Type “My name is “ + Manipulate data with “Calculate” 1 Add “Calculate” 2

52 52 Manipulate data with “Calculate” Select “Value” from the list

53 53 Manipulate data with “Calculate” Connect “Calculate” and “Console”

54 54 Manipulate data with “Calculate” Select “WriteLine” function Select “value” data

55 55 Manipulate data with “Calculate” Save and run diagram

56 56 Manipulate data with “Calculate” Execution results Type your name

Presentation on theme: "Lecture 2 Announcements Home Computers and/or Laptops/Notebooks By now you should have installed Java SE 8 and jGRASP on your computers, set up the becker.jar."— Presentation transcript:


2 Lecture 2 Announcements Home Computers and/or Laptops/Notebooks By now you should have installed Java SE 8 and jGRASP on your computers, set up the becker.jar file, and started working with some of the files from Lecture 1. How many have done this successfully? How many have tried to do this and have still not gotten jGRASP to compile and run? If you have your laptops with you, I will stick around for a bit after today's class to see if we can get you up and running. I'll also stick around for a bit after next Wednesday’s class. I've added a TROUBLESHOOTING walk-through page to the BIT115 website if you are getting the jGRASP wedge2 PATH error. This should be fixed with the latest version of jGRASP, but just in case… IMPORTANT! Always download files from the web site, save them to a local folder, and run them from there. If you try to run them directly off the site, they go in the browser cache and get renamed, and then things won't work! There are other issues to remember, which we'll cover in today's class. NOTE: It is essential that you get jGRASP working on your home machines or laptops if you are going to be successful in this class (unless you are going to do all your coding on the PCs here at the college). 2

3 3 Assignment 1 (LECTURE 5) Monday, April 20 Assignment 2 (LECTURE 8) Wednesday, April 29 Assignment 1 Revision (LECTURE 10) Wednesday, May 6 Assignment 2 Revision (LECTURE 12) Wednesday, May 13 Assignment 3 (LECTURE 13) Monday, May 18 Assignment 3 Revision (LECTURE 16) Monday, June 1 Assignment 4 (LECTURE 20) Wednesday, June 10 Assignment 4 Revision (LECTURE 21) Monday, June 15 Assignment Dates

4 Lecture 2 Announcements Attention: Windows 8 Users THIS SHOULD BE FIXED IN WINDOWS 8 NOW! But… If you are having trouble getting the software to install, one way to bring compatibility to install the Java SE JDK and jGrasp, etc, is to download and install a program called Classic Shell:;1 4

5 It's okay if right now you are feeling somewhat overwhelmed, nervous, confused, or just scared spitless! perfectly natural Hey! You're learning a new language (Java) and a new way of thinking about things, so it is perfectly natural if you're feeling a bit overwhelmed right now, or a bit nervous, or even a bit confused. Knowing this, we'll be taking baby steps for the next few lectures. I'll be holding your hand and walking you through Java and code step-by-step. So: Do not be afraid to ask questions! And: Do not be afraid to come see me during my office hours (or by special appointment). Also: please email me at if you have any questions. If it concerns code that you are working on please remember to attach file to the email so I can have a look to determine where a problem might Finally: Once I know the exact days, times, and places, going to the Open Labs for additional one-on-one help is greatly encouraged! 5

6 Some Sites/Links of Interest Udacity – Free Online Courses Udacity MIT OpenCourseWare – Free Online Courses MIT OpenCourseWare Coursera – Free Online Courses Coursera Standford Engineering Everywhere – Online CS Courses Standford Engineering Everywhere Academic Earth – Online CS Courses Academic Earth Khan Academy – Free Online Tutorials Khan Academy Code Academy – Interactive Code Learning Code Academy Code School – Interactive Code Learning Code School CoderDoJo – Code Club Community CoderDoJo – Code Club Community Girls Who Code – Code Club Community Girls Who Code Girl Develop It – Code Club Community Girl Develop It 6

7 Reading Assignment for Today Chapter 1.5: Types of Errors Chapter 1.4.5 – Tracing Code Note : there are ‘BIT 115 Student Open Source Guides’ that students wrote from previous quarters that may deal with the various topics of your readings and lessons.BIT 115 Student Open Source Guides This is a great tool, and highly recommended! 7 Lecture 2 Announcements

8 8 Quarter-Long Game Plan: Up until the Mid-Term: –1 st part of the quarter Overview of topics, conceptual understanding, not as much free- form problem-solving After the Mid-Term: –2 nd part of the quarter Focus on learning and more problem-solving on your own

9 9 Save A Copy Of All Work (Highly recommended!) In-Class Exercises, Exams, Quizzes, etc. –If you work with someone, make sure each of you gets a copy –For In-Class Exercises, you do not have to turn it in (I’ll be checking it as I walk around and watch you work) If you lose track of it, and I unintentionally record it incorrectly in StudentTracker, then whatever I’ve got will stand as the grade. Best then to save your work for proof, if needed, in the event of a discrepancy. If you do find a grading error in StudentTracker, then please don't hesitate to let me know!

10 10 Quizzes and Exams Starting next lecture, you should assume that the quizzes and exams will all be 100% pen/pencil-and-paper. You bring the pen or pencil, I’ll supply the paper –Start Practicing Now (My Mantra: Practice! Practice! Practice!) Try writing code from memory, and/or using Notepad or NotePad++ and then copy-and-pasting into jGRASP to check your work

11 BIT 115: Introduction To Programming11 Assignment 1LECTURE 5 Assignment 1 is due LECTURE 5 Monday, April 20 th in StudentTracker, by midnight –It’s posted on the website under Assignments –It will be due by midnight on day of Lecture 5 If you are confused, bring your work to class, in electronic form, and we will go over how to hand in (upload) the homework: Student Tracker (We’ll go over this in a moment with “Rex Winkus”) How to Use Student Tracker (Instructions) Student Tracker How to Use Student Tracker If you’re stuck, seek help! –Talk to the Instructor or a classmate or Open Lab helper –Email me HOMEWORKHOMEWORK

12 12 A Quick "Peek" at Assignment 1 Let's Have a Quick Look at Assignment 1 (so there are no unforeseen “surprises” down the road!) Assignment 1 is due LECTURE 5: Monday, April 20 th (uploaded to StudentTracker by midnight) What You Need To Turn In to StudentTracker for A1

13 StudentTracker Walk-Through 13

14 BIT 115: Introduction To Programming14 And now …. The Quiz! We will have our very first 'warm-up' Quiz starting next Monday NO Warm-Up QUIZ TODAY Student Tracker Instead, We looked at Student Tracker…

15 BIT 115: Introduction To Programming15 Today’s Topics Errors: How to find and fix them Dissecting the Code: What it means and what it does –opening and working Files How to set up a City Tracing Code –Predicting What A Program Will Do BEFORE you Run It Important Java and OOP Terms –like Class, Object, Method, Parameter, etc

16 Three Types of Errors 16

17 Chapter 1.5: Types of Errors 17 3 Different General Categories of Errors: Compile-Time Errors (or Syntax Errors) Run-Time Errors (or Application Errors) Intent Errors (or Logical Errors)

18 An Historical Side Trip: Why Are Bugs Called Bugs? 18 Use of the term "bug" to describe inexplicable defects has been a part of engineering jargon for many decades and predates computers and computer software; it may have originally been used in hardware engineering to describe mechanical malfunctions. For instance, Thomas Edison wrote the following words in a letter to an associate in 1878:Thomas Edison In 1946, when computer pioneer Grace Hopper joined the Harvard Faculty at the Computation Laboratory to work on the Mark II and Mark III computers. Operators traced an error in the Mark II to a moth trapped in a relay, coining the term “bug.” This bug was carefully removed and taped to the log book. Stemming from the first bug, today we call errors or glitches in a program a bug.Grace HopperMark IIMark III It has been just so in all of my inventions. The first step is an intuition, and comes with a burst, then difficulties arise — this thing gives out and [it is] then that "Bugs" — as such little faults and difficulties are called — show themselves and months of intense watching, study and labor are requisite before commercial success or failure is certainly reached.

19 19

20 Compile-Time Errors (or Syntax Errors) 20 Anything that goes wrong when you compile the file is a compile-time error! Point out that the Output Panel is often small, but it can be resized, and you should get used to figuring out which line the error pertains to. Java is case sensitive - Java is different from java, is different from JaVa - This means you must type in names, etc, EXACTLY the same File name MUST be the same as the class name that has the main method You need the import becker.robots.*; at the top of each robot file Forgetting to Compile BEFORE Running - You need to compile the file EVERY SINGLE TIME you change it - You should also wait UNTIL the compilation finishes BEFORE trying to run it Strategy For Fixing Compile-Time Errors: Follow the debugging strategy (listed in your text) to find and correct the syntax errors in the program later this evening when you do your In-Class Exercises. 1. Compile the program to get a list of errors; 2. Fix the most obvious errors, beginning with the first error reported 3. Compile the program again to get a revised list of the remaining errors.

21 Run-Time Errors (Application/Crashing Errors) 21 Anything that causes the program to crash while it's running. If you encounter a run-time error when you are compiling and running your Java programs, then this would be a jGrasp problem, or a Windows Operating System problem, and NOT a Java Problem. The Java language does a lot to protect you from this type of error, so you shouldn't see many of these. Intent Errors (Logical Errors) The program compiles and runs without crashing, but it doesn't do what you want it to. Example: - Robot takes an extra leftTurn, and runs off the screen - Robot doesn't pick up a Thing when it's supposed to. - Robot collides with a Wall (the book calls this a run-time error, but it technically isn’t) As you continue learning to code you'll make fewer "typo" type mistakes, and end up with more Intent errors then Compile-Time errors. You need to come up with a personal strategy to figure out where the Intent problems are, and how to fix them. One Option: Use a Program Debug Table (show where this is on web site) Program Debug Table

22 Lecture 2 ICE: Finding And Fixing Errors In Your Program BIT 115: Introduction To Programming22 In-Class Exercise Directions 2.1 In-Class Exercise Directions Program Debug Table We'll Wait and Do All the ICEs Together at the End of Lecture

23 Dissecting the Code 23

24 24 Downloading and Working Files Under Course Wide Information If you have the Java JDK and jGRASP properly installed, files you download from the BIT115 web site should be associated with jGRASP. This means they will appear with with jGRASP “G” icon. Typically, all you have to do to open file is to simply double-click on it and it will open automatically in Files Should Be Associated to jGRASP Important Always download files from the web site first to a folder on your computer or USB thumb drive before opening and working on them. If you work on files from the browser cache, the file names can be changed and then the class name will no longer match up and your programs won’t run correctly. Also the browser cache likes to append numbers to the file name if you have already downloaded that file previously, which also means the class name won’t match the file name. Alternatively, you can open jGRASP and select the file from the menu bar through File > Open or else to the simply drag-and-drop the file into the work window.

25 Dissecting the Code: What It Means and What It Does ( 25 1 import becker.robots.*; 2 3 4 public class Quiz2 extends Object 5 { 6 public static void main(String[] args) 7 { 8 City toronto = new City(); 9 10 Robot Jo = new Robot(toronto, 0, 3, Direction.NORTH, 0); 11 12 new Thing(toronto, 2, 2); 13 new Wall(toronto, 3, 3, Direction.EAST); 14 new Wall(toronto, 3, 3, Direction.NORTH); 15 new Wall(toronto, 3,3, Direction.SOUTH); 16 17 Jo.turnLeft(); 18 19 } 20 }

26 import becker.robots.*; 26 This imports from the becker.jar collection all the classes contained in the robots file so they would be functionally available in Java (JDK) and any code written using it. These classes include the Robot.class, the Thing.class, the City.class, the Wall.class, and over a hundred more. NOTE: Java loads some classes by default into the compiler, while others it does not. Later on we will have to import additional Java classes in our code to get our programs to work becker.jar

27 public class Quiz2 extends Object 27 Java, like other object-orientated languages, supports class inheritance. Inheritance allows one class to "inherit" the properties of another class. For example, all Java objects are inherited from the java.lang.Object class which is a fundamental part of Java and the Java libraries. Our Quiz2 class is inheriting the properties of Java's Object class, and so extends its actions and attributes in the program hierarchy. 'public' so other classes can use it. public class Quiz2 extends Object a 'class' is a blueprint for making 'objects' that can do something 'Quiz2' is the name of the class. It can be any name (but must match file name if it contains main). The program uses this name when it runs to know what 'objects' and 'methods' to use in the program.

28 public static void main(String[ ] args) 28 The method is public because it is accessible to the JVM (Java Virtual Machine) to begin execution of the program, and can be accessed by any other class or method. The static keyword signifies the fact that this method can be invoked without creating an instance of that class (an object). Main is called before any objects are made, hence static. void signifies that this method does not return anything. In other words no new or altered data is sent out from it for use by the rest of the program. Nothing is returned, so void. Just like in the C “procedural” language and other languages, this is the main method in a Java program. When you run a Java program, execution begins in the main method. String is the data type that could be passed to the method, although no data type needs to be passed. An example of a data type is an int or float. The [] represents unknown quantity. args is the name of the parameter. We can pass any number of arguments to this method. Note Note: main is a method() inside a Class

29 City toronto = new City(); 29 We want to make a new instance of the City class (City.class) found in the becker > robots directory (inside becker.jar) and call this new object Toronto The City class contains all the attributes and actions necessary to set up a city when a named city object (like toronto) is created, include shape, size, color, streets, avenues, etc. By itself, the City class can't do anything. It's just a collections of ideas and concepts. You need an object made from the City class (like toronto here) to actually do something with a city. Names the object  Creates the new City object NOTE: In Java, '=' is an assignment operator, and points right to left; "==" is an equals sign. EXAMPLE: x = 1 assigns 1 to variable space x and x == 1 means x equals 1.

30 30 1 import becker.robots.*; 2 3 4 public class Quiz2 extends Object 5 { 6 public static void main(String[] args) 7 { 8 City toronto = new City(); 9 10 Robot Jo = new Robot(toronto, 0, 3, Direction.NORTH, 0); 11 12 new Thing(toronto, 2, 2); 13 new Wall(toronto, 3, 3, Direction.EAST); 14 new Wall(toronto, 3, 3, Direction.NORTH); 15 new Wall(toronto, 3,3, Direction.SOUTH); 16 17 Jo.turnLeft(); 18 19 } 20 }

31 Robot Jo = new Robot(toronto, 0, 3, Direction.NORTH, 0); 31 Our instance of the Robot object is named Jo Jo is placed in a City called Toronto Jo is starting out on Street 0 Jo is starting out on Avenue 3 Jo is starting out facing North Jo is starting out with 0 (zero) Things in its backpack Now, another way to "construct" this is with only four parameters, by leaving on the number of Things in the backpack Names the Robot  Creates the new Robot using five parameters Robot Jo = new Robot(toronto, 0, 3, Direction.NORTH); If you are not going to be picking up or putting down Things in your program, then you can "construct" your Robot without this fifth 'backpack' parameter. Later on, when we start creating our own types of Robots and methods, some of the ICES will be set up in such a way that parts of the code will use five parameters and other parts of the code will use four parameters and this will cause an error. We'll go over this in greater detail when the time comes.

32 BIT 115: Introduction To Programming32 new Thing(toronto, 2, 2); new Wall(toronto, 3, 3, Direction.EAST); new Wall(toronto, 3, 3, Direction.NORTH); new Wall(toronto, 3, 3, Direction.SOUTH); These will work by default. For stuff that just sits there, we don’t have to actually give them unique names (e.g., BrickWall) but we can’t talk about them in code, however a Robot can pick up/put down an unnamed object. Why would you want to give a wall a unique name? If you look at the becker library you will discover that Wall actually extends Thing, that is to say Wall has inherited all the initial properties of Thing Jo.turnLeft(); turnLeft() is one of the methods of the Robot class, along with move(), pickThing(), putThing(), frontIsClear(), countThingsInPackback(), and several more. Because Robot can turn left, Jo can turn left.

33 Something to Remember: In parameter order, street comes first and avenue comes second. Streets go West-East (left-right) Avenues go North-South (up-down) A neat trick to remember the difference is to recall that the 'A' and 'V' in Avenue point up and down.

34 Lecture 2 ICE: Setting Up a City BIT 115: Introduction To Programming34 In-Class Exercise Directions 2.2 We'll Wait and Do All ICEs Together at the End of Lecture

35 Chapter 1.4.5 – Tracing Code BIT 115: Introduction To Programming35

36 BIT 115: Introduction To Programming36

37 BIT 115: Introduction To Programming37

38 Important Terms to Remember 38

39 BIT 115: Introduction To Programming39 Some Important Terms To Remember Under Course Wide Information An object receives all of the characteristics of a class, including all of its default data and any actions that can be performed by its functions. The object is for use with specific data or to accomplish particular tasks. A method simply refers to a function that is encased in a class. It usually entails an action. A parameter is a variable that is passed into a function that instructs it how to act or gives it information to process. Parameters are also sometimes called arguments. A field or property is a default set of data stored in a class. A class can have multiple properties and can be changed dynamically through the methods of the class. These are sometimes called attributes. Inheritance is one of the keys that make OOP tick. Simply put, classes can inherit methods and fields from other classes by extending them and each class can be extended by multiple classes. This means that you can start with a base (or parent) class that contains shared characteristics among several classes. That base class can then be extended by other classes (children) that are similar but are meant for slightly different purposes. Any changes in the parent class will automatically cascade to its children. A class is a set of functions that can work together to accomplish a task. It can contain or manipulate data, but it usually does so according to a pattern rather than a specific implementation. An instance of a class is considered an object. Until an object is instantiated from a class, the class can’t actually do anything.

40 BIT 115: Introduction To Programming40 Class Class (The “Idea” of Features and Functions) Under Course Wide Information The Robot class. The Robot class contains all the features and functions that a robot might have once it is created (or instantiated) as an object. Until then, all the Robot features and functions are just the idea how a robot might work, but being an idea the class doesn’t do any work itself.. Just like we might have an idea how a car should look and operate—body, engine, four tires, steering wheel, gas and brake pedals, etc—an idea of a car is not the same of an actual working car. Here the idea of a car is a class, and an actual working car is an object. A class is a collection of functions that can work together to accomplish a task. It can contain or manipulate data, but it usually does so according to a pattern rather than a specific implementation. An instance of a class is considered an object. Until an object is instantiated from a class, the class can’t actually do anything. Example

41 41 "Car" Class "Car" Object "Engine" "Chassis" "Wheels" "Brakes" "Power" "Transmission" "Seats" "Lights"

42 42 "Car" Class "Car" Object "Engine" "Chassis" "Wheels" "Brakes" "Power" "Transmission" "Seats" "Lights" No "Wings” Here

43 BIT 115: Introduction To Programming43 Object Object (An Instance of the “Idea” Made Actionable) Under Course Wide Information When we create an object from the Robot class we do so by creating a named instance of the Robot class that will possess all the features and functions that were outlined as belonging to the Robot class as an idea. Once the object is instantiated, what was once the idea of a Robot now becomes an actual Robot that possesses specific ‘Robot’ properties (its shape, size, color, speed) and that can perform specific ‘Robot’ actions (like move, turn left, put down a thing, pick up a thing, etc). Example An object receives all of the characteristics of a class, including all of its default data and any actions that can be performed by its functions. The object is for use with specific data or to accomplish particular tasks.

0 thoughts on “Iti1120 Assignment 47

Leave a Reply

Your email address will not be published. Required fields are marked *