Unit 1 and 2 Ideas
ideas for how to incorporate units 1 and 2 into our lessons + cars
Unit 1: Primitive Types
- primitive: int, double, boolean
- variable store data
- import scanner to add user input
- +: addition symbol
- used to add two numbers.
- -: subtraction symbol
- used to subtract two numbers.
- *: multiplication symbol
- used to multiply two numbers.
- /: division symbol
- used to divide two numbers.
- %: modulo operator
- used to find the remainder of the division of two numbers.
- compound operators
- a = a + 1 same as a += 1 or age ++
-
casting to change between different data types
-
used in calculating the price of a car
- add different features with different prices
- getting on highway 2 cars at a time
- total cars gotten on highway is car += 2
- casting can be used for estimates
- take the true speed of the car as double round to int to show driver without too much confusion/too many numbers
Unit 2: Using Objects
- objects: reference types
- reference to stored data
- class: defines object
- constructor: makes the data that will be stored in object
- method made up of five parts: the scope, the return type, the name, the parameters, the body
- scope: public/private - who can access code
- return type: void (nothing is returned)
- name: name of method
- parameters: what is added to the constructor (the data)
- body: what the method does
- math class
- abs(int a): absolute value of the argument as an int or double, depending on whether you put in an int or double into the argument
- pow(double a, double b): value of a raised to the power of b as a double
- sqrt(double a): square root of the argument as a double
- random(): s a random number between 0 (inclusive) and 1 (exclusive) as a double
- constructor that creates different features to be stores in an objects
- Car(String brand, String model, int year) Car flash = new Car("BMW", "X7", 2023);
- use math class find acceleration - positive or negative