Rohan G Units 1-5 Vocabulary Terms
Week 14 Units 1-5 Vocab Terms Blog
- Most notes are embedded within each lesson for units 1-5, but here are the terms I was unsure where to put in a unit blog
- Terms
- Casting (Division)
- Casting (Truncating and Rounding)
- Concatenation
- Java Math Class
- Truth Table
- De Morgan’s Law
- Comparing Numbers
- Comparing Strings
- Comparing Objects
- Constructors
- Accessor and Mutator Methods
- Access Modifiers
- Inheritance and Extends with Examples of Subclass and Super Keyword
- Method Overloading
int top = 4;
int bottom = 9;
double division = top / bottom;
System.out.println("Without Cast: "+ division);
double division = ((double) top) / bottom;
System.out.println("With Cast: "+ division);
double blah = 6.99999935629148437124097925792348972398472983749283749823749832478923;
System.out.println("Non-truncated: " + blah);
int blahhehe = (int) blah;
System.out.println("Casted and Truncated:" + blahhehe);
String blah1 = "monkey ";
String blah2 = "adi";
System.out.println(blah1+blah2);
String monkey = blah1 + blah2 ;
int blah = 5;
System.out.println(blah + " " + (monkey) + "s");
import java.lang.Math;//must be imported at start of program
double rand = Math.random();
System.out.println("random: " + rand);
System.out.println("Cos: " + Math.cos(rand));
System.out.println("Log: " + Math.log(rand));
System.out.println("Square Root: " + Math.sqrt(rand));
boolean a = true;
boolean b = false;
!(a && b) == (!a || !b);
!(a || b) == (!a && !b);
int x = 1;
int y = 1;
int z = x + 2;
if(x == y){
System.out.println("true");
}else{
System.out.println("false");
}
if(x == z){
System.out.println("true");
}else{
System.out.println("false");
}
let score = 0
let total = 0
let count = 0
let correct = 0
class Jeopardy {
constructor(question, answer, point) {
this.question = question;
this.answer = answer;
this.point = point;
}
// REAL BIG BOY IMPLEMENTATION!!!
CheckAnswer(guess) {
return guess === this.answer
}
// WOO BIG BOY IMPLEMENTATION RIGHT HERE
}
let q1 = new Jeopardy('What is the capital of Chile?', 'Santiago', 2);
let q2 = new Jeopardy('What is the capital of France?', 'Paris', 1);
let q3 = new Jeopardy('What is the capital of Czech Republic?', 'Prague', 2);
let q4 = new Jeopardy('What is the capital of Portugal?', 'Lisbon', 2);
let q5 = new Jeopardy('What is the capital of Ethiopia?', 'Addis Ababa', 2);
let q6 = new Jeopardy('Who is the President of the United States?', 'Joe Biden', 1);
let q7 = new Jeopardy('Who is the leader of Russia?', 'Vladimir Putin', 1);
let q8 = new Jeopardy('What is the capital of the United States?', 'Washington DC', 1);
let q9 = new Jeopardy('What country is being invaded by Russia?', 'Ukraine', 2);
const qarray = [q1, q2, q3, q4, q5, q6, q7, q8, q9]
function QNA(number) {
for (let i = 0; i < number; i++) {
const randomValue = qarray[Math.floor(Math.random() * qarray.length)];
var index = qarray.indexOf(randomValue);
if (index > -1) {
qarray.splice(index, 1);
}
let guess = prompt(randomValue.question + " Points: " + randomValue.point);
count = count + 1
total = total + randomValue.point
if (randomValue.CheckAnswer(guess)) {
score = score + randomValue.point;
correct = correct + 1
console.getElementById('answer').innerHTML = "Well Done!";
console.getElementById('score').innerHTML = "Your score is " + score + "/" + total;
console.getElementById('correct').innerHTML = "You got " + correct + " questions correct out of " + count;
}
else {
console.getElementById('answer').innerHTML = "Nice Try!";
console.getElementById('score').innerHTML = "Your score is " + score + "/" + total;
console.getElementById('correct').innerHTML = "Sorry, you have gotten " + correct + " questions correct out of " + count;
}
}
}
function Tester() {
}
String x = new String("blah2");
String y = new String("blah2");
String z = new String("blah5");
x=y;
if(x == y){
System.out.println("true");
}else{
System.out.println("false");
}
if(z == x){
System.out.println("true");
}else{
System.out.println("false");
}
Accessor and Mutator Methods
- instance method that gets or sets the value of a property of an object.
- Getters and setters are accessor and mutator methods to retrieve and set data of a variable, respectively
- accessors access the predetermined data
- mutators change the data to set new predetermined data
public class Person {
private String name; // private = restricted access
// Getter
public String getName() {
return name;
}
// Setter
public void setName(String newName) {
this.name = newName;
}
}
void HelloWorldDefault(){
System.out.println("Hello World");
}
public void HelloWorldPublic(){
System.out.println("Hello World");
}
private void HelloWorldPrivate(){
System.out.println("Hello World");
}
protected void HelloWorldProtected(){
System.out.println("Hello World");
}
public class Animal {
private String eats;
private int numLegs;
public Animal(){}
public Animal(String food, int legs){
this.eats = food;
this.numLegs = legs;
}
public String getEats() {
return eats;
}
public void setEats(String eats) {
this.eats = eats;
}
public int getNumLegs() {
return numLegs;
}
public void setNumLegs(int numLegs) {
this.numLegs = numLegs;
}
}
public class Cat extends Animal{
private String toy;
public Cat( String food, int legs) {
super(food, legs);
this.toy="String";
}
public Cat(String food, int legs, String toy){
super(food, legs);
this.toy=toy;
}
public String getToy() {
return toy;
}
public void setToy(String toy) {
this.toy = toy;
}
}
public class Concat {
String concat(String blah, String blah2){
String blahblah = blah + blah2;
return blahblah;
}
String concat(String blah, String blah2, String blah3){
String blahblah = blah + blah2 + blah3;
return blahblah;
}
}
//no errors