This is a timed exam on computer science (data structures & algorithms). It is a TIMED exam once again and it will be open and accessible from 11:00am to 12:15 pm (MT) on Thursday, the 22nd. You will...

1 answer below »
This is a timed exam on computer science (data structures & algorithms). It is a TIMED exam once again and it will be open and accessible from 11:00am to 12:15 pm (MT) on Thursday, the 22nd. You will need to follow this link to access the exam. The login details are:username: odohtimopassword:To11041994urinrin
LET ME KNOW IF YOU HAVE ANY QUESTIONS.
https://bengalweb.isu.edu:8447/cas-web/login?service=https%3A%2F%2Felearn.isu.edu%2Fmoodle%2Flogin%2Findex.php
Also, ONLY click on this class "CS 2235 - 01, 02, 03, E1: Data Struct Alg (PMena), Spring 2021". Please don't tamper with any other class



    PowerPoint Presentation CS2235: Data Structures & Algorithms Class Lecture: January 14th ,2020 Objectives • Introduction to Java • Brief overview of the language • Highlight some key differences between Java and Python • Coding in Java • Setting up a program in Java • Declaring Variables and Print Statements • Command Line • Navigate and locating files using the Command Prompt/Terminal • Compiling and Running Java Programs • Gathering User input in Java (If time permits) Introduction to Java • Java was originally developed by Sun Microsystems in the mid 1990’s • The biggest advantage at the time was Java portable (i.e. it could be used on a PC, Mainframe, etc.) • The number of libraries available also helped spread the use of Java • At the time Java was much slower than languages such as C Introduction to Java • Java is a Class-Based programing language, just like C, C++ and Python • Java is a high level language, meaning we can understand it, but the computer cannot • In order to run a program written in Java, we must first compile our code so the computer can understand what we wrote • When we compile our programs in Java, the compiler will create a .class file which the computer can understand and will actually run Java Vs. Python • Java is a static language while Python is dynamic • Java is much faster than Python • Python is an interpreted language while Java requires a compiler • Generally Python is considered to be less complex while Java is faster Writing Code in Java: Getting Started • Writing code in Java is different than Python • In Java all code has to belong to a Class • So to start writing code in Java we must first define our class • Lets start coding the “Hello World” program as an example Defining Your Methods • Once you have defined your program’s class you can begin creating methods • Methods are functions that belong to our class and allows us to preform actions with our program • Most Java programs have a Main class, where the program begins • Now lets create the Main class for our “Hello World” program Print Statements • A print statement in Java is a bit more involved than printing in Python or C++ • A typical print statement looks like this: • System.out.println(“What I want to print”); • A couple of notes • The ‘ln’ tells the program to end the line after it prints • Every statement in Java (and C/C++) must end with a semicolon Compiling and Running a Java Program • In order to run and compile a program using the command line you must first navigate to the directory where your code is stored • Once you are in the correct directory you compile your program using the Java Compiler • The command for the compiler is “javac” • This will create the .class file needed to run your program • Now with the .class file you can use the Java Virtual Machine (JVM) to run your file. Simply type java and the name of your class file and the program will run Compiling and Running a Java Program • Some quick notes: • For windows users to open command prompt just press windows+X, click on run and type in cmd. • The name of your file and the name of your program’s class need to be the same. For example if you name your file Test.java, the program’s class need to be defined as Test • Navigating your folders using the command line and using the Java compiler is NOT case sensitive • Using the JVM to run your class files IS case sensitive • Your file name and program’s class need to be in the same case Command Line • In Windows if you forget a command simply type help and a list of the commands and a definition of what they do will be shown on your screen • Some key commands for this class: • CD Path – Change current directory to the given path • CLS(Windows)/Clear (Apple/Linux) – Clears current screen • DIR(Windows)/LS(Apple/Linux) – Displays files in current directory • Javac file_name.java – compile the given .java file • Java file_name – run the given class file Declaring Variables In Java • As with Python, you can declare a variable using any name that is not reserved • Page 3 of the text has the list of reserved words for Java • A big difference between Python and Java (as well as C/C++) is that you must specify the data type of your variable when you declare it Declaring Variables In Java • The most common data types are: • Int – Integer • Char – Unicode character • String – Array of characters • Float – 32 bit point number • Double – 64 bit point number • Boolean – True or False Declaring Variables In Java • The typical format for declaring a variable is: • Data Type – Variable Name = Value; Don’t forget the semicolon! Homework #1 • Homework 1 has been posted to Moodle. • It will be due Thursday January 21st BEFORE class • Remember to include a heading with: • First & Last Name • Course Number • Due Date • Assignment Number • You only need to turn in your .java file(s) and a screenshot (s) of your output Have a great long weekend! CS2235: Data Structures & Algorithms Class Lecture: January 19th, 2021 Objectives • Recap: Last week • Introduced Java • How to set up a Java program & declare variables • Focus on program control flow in Java • Conditionals • Loops • Logic Operators • User Input A Quick Note on Variables • When you declare a variable without assigning a value, it will be assigned a default value by Java • Numerical variables usually are assigned 0 • Booleans are assigned False • Character/Strings are assigned NULL Program Control Flow in Java • Control flow works very similar in Java as it does in C/C++, Python, etc. • The differences just lie in the syntax of the code, the overall structure is the same • If you ever get confused on how your program should be progressing a Flow Chart is a great tool to visualize your program Conditional Statements • As with Python we use IF statements to make decisions on how to run through out program • Format for an IF Statement in Java: If(Boolean Expression) Body ; Conditional Statements • If you need your program to make a response in the event your if statement is not executed you use an else statement • Format of a Boolean if statement: if(Expression) True Body; else False Body; Conditional Statements • If you need to evaluate more then 1 condition, you use the else if statement: if(Expression) 1st Body; else if(Expression) 2nd Body; else False Body; Conditional Statements • So why do we use else if statements instead of multiple if statements? • The answer lies with the efficiency of the program, • If you use multiple if statements it will check all of the statements • While using the else if statements, the program it will only check the statements until a condition is met Conditional Statements • Some notes on conditional statements: • If you only have one line statement you do not need to put any brackets • If your conditional has multiple lines use the {} brackets to block your code or it will not work • To start the conditional you do not need a semicolon, BUT you still need them at the end of each line inside the conditional block Conditional Statements Switch Statements • In the event you have several different outcomes for your conditional statement Java, C/C++ have a switch statement to help with efficiency • When using a switch statement you define each possible outcome using a Case • Everything else is covered by the default block • Remember when using a switch statement to end each case with a break statement to end the sequence Switch Statements • Switch statement format: Switch(variable){ Case condition: Outcome; Break; Default: Outcome; } Switch Statements Rules • Duplicate values for a case statement are not allowed. • The value for a case must be of the same data type as the variable in the switch. • The value for a case must be a constant or a literal. It cannot change during the statement execution • The break statement is optional. If omitted, execution will continue on into the next case. • The default statement is also optional and need not be at the end of the statement. • In the event that the default statement is not at the end, then a break statement must be put after the default statement to omit the execution of the next case statement. Loops • Java has 4 common types of loops: • While • For • Do While • For Each While Loops • The while loop is generally considered the simplest loop • It is an indefinite loop, so it will run until a condition is met • As such it is very possible to end up in an infinite loop if you are not careful • If you end up in an infinite loop just press Ctrt + C to force the program to end • Basic format in Java: While(Condition){ Loop Body; } Do-While Loops • Another form of the while loop • A do while loop allows for the condition to be checked at the end of an iteration rather than at the beginning • Format of a do while loop in Java: do { Loop Body } while (condition) ; For Loops • For loops are definite loops, meaning when the loop starts we know how many iterations the loop is going to run through • Format of a for loop in Java: for(initializer/start; condition/end; increment){ Loop Body; } For Loops • Typically the initializer is defined with an i or j • Remember you have to declare the type ( its always an integer) • To increment one number up use ++ • To increment one number down use -- • A for loop is just a predefined while loop: { Initialization; While(Condition){ Body; increment; } For Each Loops • In Java it is common to have to loop through a collection or structure,
    Answered 4 days AfterApr 17, 2021

    Answer To: This is a timed exam on computer science (data structures & algorithms). It is a TIMED exam once...

    Pulkit answered on Apr 22 2021
    150 Votes
    test is completed
    SOLUTION.PDF

    Answer To This Question Is Available To Download

    Related Questions & Answers

    More Questions »

    Submit New Assignment

    Copy and Paste Your Assignment Here