Algorithms and Computer Programming
Algorithms algorithm is an ordered sequence of instructions for solving a problem. Look at it as a building blocks consist of variables, subroutines, parameters, conditionals, and repetition.
Variables: Named values variables give us the ability to refer to values unambiguously. Another way to think of a variable is like a named box that stores a value. For instance int x = 5; String x = “hello”;
Conditionals: Handling different situations Get the algorithms to do different things depending on whether certain things are true or not if something is true: then do something else: do something else
Repetition Sometimes we need our algorithm to do things again and again. Repeat action(s) until a desired condition is met. While some condition is met, repeat action(s). Repeat action(s) a fixed number of times.
Subroutines: Named helper algorithms Many algorithms require the use of some common, or more basic, operations. In fact, most algorithms we write refer to some other algorithms. For instance, in an algorithm that keeps track of how many times a repeated action has occurred, we may want to increment, or add one to some counter variable, as in counter = 1 + counter
Parameters: Named inputs start = input("Enter a number: ")
constant cannot be changed during the execution of the program int x = 5; int z = x + 2
Parameter passed to the subroutine String x = “Z is = ” ; int z = 6 System.out.print(x + z);
differentiating between a function and a procedure. A function returns a value and a procedure just executes commands. function comes from math. It is used to calculate a value based on input. A procedure is a set of command which can be executed in order.
Using pseudo code
abbreviated from American Standard Code for Information Interchange ASCII
Ω or kΩ Ohms to kilo ohms 100 Ω = 0.1 kΩ 1000 Ω= 1 kΩ From Ω to kΩ divide by 1000 From kΩ to Ω multiply by a 1000
Objects All objects have state and behaviour. Dogs have state (name, colour, breed) and behaviour(barking, fetching, eating). Bicycles also have state (current gear, pedal, colour) and behaviour (Changing gear, brakes). What state can objects have? What behaviours can objects perform?
Software objects States (variables, methods, programming language) Behaviours (functions, transactions)
Class There are thousands of bicycles with same models and make, each bicycle build from the same set of blueprints Class is the blueprint of the objects you created Example Bicycle is an instance of class objects bicycles
Public class Bicycle int speed = 0; int value ; int increamnetspeed; String model;
Inheritance Classes are allowed to inherent from the super classes Example Bicycle Superclass Mountain bike and Road bike inherence from bicycle
Method start = input("Enter a number: ") System.out.println(“Text”); Parameters: Named inputs
Attributes in Computing An attribute is another term for a field. It's typically a public constant or a public variable that can be accessed directly. In this particular case, the array in Java is actually an object and you are accessing the public constant value that represents the length of the array. In computing, an attribute is a specification that defines a property of an object, element, or file. It may also refer to or set the specific value for a given instance of such. An attribute is frequently and generally a property of a property. However, in actual usage, the term attribute can and is often treated as equivalent to a property depending on the technology being discussed.computingvalue
int x = 10; Variable Value of Double Temperature = 36.9
Scanner input = new Scanner(System.in); String number = input.nextLine();
Write a program to convert the weather temperature from Celsius (°C) / Fahrenheit (°F) Conversion
Write a program to find the area of a circle First you ask the user to input radius The out put Radius * Radius *3.14 PI: 3.14 NO numbers should be used in RESULT
Write a programme to calculate number of strings
Write a programme to calculate number days
Write a programme to reverse entries