Record of Week 0 and 1 Hacks

  • Modified and personlaized index.md with informatin and a picture about myself
  • Changed style in config.yml and tested out a lot of idffernet themes and settled with midnight theme
  • Worked on Java Hello and Console Hacks, completing hacks for a “rock, paper, scissors” game
  • Added Commonly used Linux Commands to the Lab Notebook and created a Python Quiz About it
  • Added a “Why I love my tools” post which focused on github and vscode

Record of Week 2 Hacks

  • Worked on JS Output w/ jquery Hacks, where we used html and javascript tables to display information
  • Personalized tables from cars, to information about players in the NFL
  • Worked on styling HTML tables using W3 Schools
  • Worked on Lab Notebook Hacks for Week 1: IPYNB Table, Code

Shivansh Goel Lab Notebook

Linux Commands that we use Frequently

ls - list all items in a directory

cd - change directory

mkdir - make directory

sudo - enter admin priveleges

code - enter into GUI (vscode)

git clone - clones git repository into own

cat - view a file

import getpass, sys

# method to display question and get user's answers
def question_with_response(prompt, qCount):
    print("Question " + str(qCount)  + " : " + prompt)
    msg = input()
    return msg

# dictionary to hold questions and answers as key : value pairs
questionsDict = {"What does the command 'ls' do": "list all items in a directory",
    "What does the command 'cd' do": "change directory", 
    "What does the command 'mkdir' do": "make directory",
    "What does the command 'sudo' do": "enter admin priveleges",
    "What does the command 'code' do": "enter into GUI (vscode)",
    "What does the command 'git clone' do?": "clones git repository into own computer",
    "What does the command 'cat' do": "views a file"
}

# number of questions as length of the dictionary
questions = len(questionsDict)

# set correct to 0
correct = 0


print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
print("Are you ready to take a test! Press Enter key to begin. Best of luck :)")
input()

questionCount = 0
# iterate over list of keys from the dictionary. pass dictionary key as question to the question_with_response function
for key in questionsDict:
    questionCount += 1
    rsp = question_with_response(key, questionCount)
    # compare the value from the dictionary to the user's input
    if rsp.lower() == questionsDict[key].lower():
        print(rsp + " is correct! Good Job!")
        correct += 1
    else:
        print(rsp + " is incorrect! Better Luck next time.")

# print final score    
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))

# calculate percentage
page = correct/questions * 100

# print percentage


print("Total Percentage: " + str (format(page,".2f")) + "%")
Hello, shivansh running /home/shivansh/anaconda3/bin/python
You will be asked 7 questions.
Are you ready to take a test! Press Enter key to begin. Best of luck :)
Question 1 : What does the command 'ls' do
list all items in a directoryh is incorrect! Better Luck next time.
Question 2 : What does the command 'cd' do
change directory is correct! Good Job!
Question 3 : What does the command 'mkdir' do
make directory is correct! Good Job!
Question 4 : What does the command 'sudo' do
enter admin priveleges is correct! Good Job!
Question 5 : What does the command 'code' do
enter into GUI (vscode) is correct! Good Job!
Question 6 : What does the command 'git clone' do?
clones git repsoitory into won computer is incorrect! Better Luck next time.
Question 7 : What does the command 'cat' do
views a file is correct! Good Job!
shivansh you scored 5/7
Total Percentage: 71.43%

Notes for this Hack:

A basic Review for Linux Commands which is important for basic function around the computer to access the different github repositories that I need to use for the class

Basic Java Concepts

method: In Java, a method is a block of code that performs a specific task or action.

main method: In java, a main method is the entry point when your run the java application.

variables:

Java Hello Hacks

// Hack 1: Explain Anatomy of a Class in comments of program (Diagram key parts of the class).
// Hack 2: Comment in code where there is a definition of a Class and an instance of a Class (ie object)
// Hack 3: Comment in code where there are constructors and highlight the signature difference in the signature
//Hack 4: Call an object method with parameter (ie setters).
// Definition of the class
public class Person
{
    // body of the class
    // Method of Class
    public void information(int age, String email, double salary){
        System.out.println("User is: " + age + "years old!");
        System.out.println(age);
        System.out.println(email);
        System.out.println(salary);
    }
    
    public static void main(String[] args) {
        // Instance of the Class
        Person shivansh = new Person();
        
        // Calling an object method with parameters
        shivansh.information(10, "testing", 20.5);
    }
    

}

Java Hello Hacks Additional Requirements

public class Class1 {

    public void Person(String name, int age){
        System.out.println("The name of the person is: " + name + "The age of the person is: " + age);
    }

    public void Dessert(String type, int cost) {
        System.out.println("The type of the dessert is: " + type + "The cost of the desert is: " + cost);
    }

    public static void main(String[] args){
        Person person1 = new Person("Person1", 15);
        Dessert dessert1 = new Dessert("Ice Cream", 15);
    }    

}
import java.util.ArrayList; // import the ArrayList class

// Go through progression of understanding a Static Class. Build a purposeful static Class, no Objects.
    
// Calculate stats functions on an array of values: mean, median, mode.
ArrayList<Integer> numbers = new ArrayList<Integer>();
numbers.add(1);
numbers.add(2);
numbers.add(2);
numbers.add(3);
numbers.add(3);
numbers.add(4);
numbers.add(4);
numbers.add(5);
// Getting speciifc values from the ArrayList
int x = numbers.get(1);
System.out.println(x);
System.out.println(numbers.get(0));
// Calculating Mean from ArrayList
int y = numbers.get(0) + numbers.get(1) + numbers.get(2) + numbers.get(3) + numbers.get(4) + numbers.get(5) + numbers.get(6) + numbers.get(7);
int z  = y/8;
System.out.println(z);



2
1
3

Java Console Hacks

// Showing the use of Hashmaps, Arrays, and Arraylists
import java.util.ArrayList; // import the ArrayList class
import java.util.HashMap; // import Hashmap Class

// Fixed Array 
int[] numbers = {1, 2, 3, 4, 5};
System.out.println(numbers);
// ArrayList
ArrayList<String> integers = new ArrayList<String>();
    integers.add("1");
    integers.add("2");
    integers.add("3");
    integers.add("4");
    System.out.println(integers);
// Different methods using ArrayList
// Changing at item in arraylist
integers.set(0, "1");
// Hashmap 
HashMap<String, Integer> people = new HashMap<String, Integer>();
// Putting A Person Name and their Age
people.put("Person1", 15);
people.put("Person2", 16);
people.put("Person3", 17);
people.put("Person4", 18);
System.out.println(people);





[I@169a8ed0


[1, 2, 3, 4]
{Person1=15, Person2=16, Person3=17, Person4=18}
import java.util.Scanner;
import java.util.Random;

public class RockPaperScissors {
    public static void main(String[] args) {
        // Getting input from the user
        Scanner scanner = new Scanner(System.in);
        
        System.out.println("Choose one: rock,paper,scissors");
        String playerMove = scanner.nextLine();
      
        // Getting input from the Opponent
        Random random = new Random();
        int othernumber = random.nextInt(3);

        String opponentMove;
        // If, else if, else statement:
        if (othernumber == 0) {
            opponentMove = "rock";
        } else if (othernumber == 1) {
            opponentMove = "paper";
        } else {
            opponentMove = "scissors";
        }
        System.out.println("Opponest chose: " + opponentMove + "!");
        // Printing out opponent Move
        
    }
}

Reviewing the 10 Units of Computer Science A and how identifying if we used them

Unit 1: Primitive Types

Unit 2: Using Objects

Unit 3: Boolean Expressions and if Statements

Unit 4: Iteration

Unit 5: Writing Classes

Unit 6: Array

Unit 7: ArrayList

Unit 8: 2D Array

Unit 9: Inheritance

Unit 10: Recursion

I applied Arrays, ArrayLists, Primitive Types, and Using Objects in the code above

Answer why you think this reorganization and AP indetification is important?

Reorgnaizations aad AP identification is important because they show what pices of code you are suppossed to use for your individual projects and requirments. It also shows where you are at in terms of using the various skills in Java and if you are at AP standards

Review of Week 1 Hacks

What did I learn of Week 1 Hacks:

  • From the Java Hello Hacks I learned all the different parts of a class and how they function together
  • Also From the Java Hello Hacks I learned how to create static methods and calling them from an instance of the class
  • From Java Console Hacks I learned about how to use fixed array, Arraylist, and Hashmap. Out of these three, I think that Hashmap definetly is the most interesting to me.
  • Also From the Java Console Hacks I became more prficient in the use of Scanners and to gain user input.
  • Lastly, I learned about the 10 differnet units for AP Computer Science A and learned if I can maybe apply them in future programming

Week 2 Hacks: HTML Table Hacks

Hacks:

  • Make your own tables, with data according to your interests.
  • Describe a benefit of a markdown table.
  • Try to Style the HTML table using w3schools.
  • Describe the difference between HTML and JavaScript.
  • Describe a benefit of a table that uses JavaScript.
%%html

<!-- Head contains information to Support the Document -->
<head>
    <!-- load jQuery and DataTables output style and scripts -->
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css">
    <script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>var define = null;</script>
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
</head>

<!-- Body contains the contents of the Document -->
<body>
    <table id="demo" class="table">
        <thead>
            <tr>
                <th>Player</th>
                <th>Position</th>
                <th>Height</th>
                <th>Age</th>
                <th>Weight</th>
                <th>Team</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Patrick Mahomes</td>
                <td>Quarterback</td>
                <td>6ft 2</td>
                <td>27</td>
                <td>225</td>
                <td>Kansas City Chiefs</td>
            </tr>
            <tr>
                <td>Tyreek Hill</td>
                <td>Wide Reciever</td>
                <td>5ft 10</td>
                <td>29</td>
                <td>185</td>
                <td>Miami Dolphins</td>
            </tr>
            <tr>
                <td>Jaylen Waddle</td>
                <td>Wide Reciever</td>
                <td>5ft 10</td>
                <td>24</td>
                <td>185</td>
                <td>Miami Dolphins</td>
            </tr>
            <tr>
                <td>Ja'Marr Chase</td>
                <td>Wide Reciever</td>
                <td>6ft 0</td>
                <td>23</td>
                <td>201</td>
                <td>Cinciniati Bengals</td>
            </tr>
            <tr>
                <td>Joe Burrow</td>
                <td>Quarterback</td>
                <td>6ft 4</td>
                <td>26</td>
                <td>216</td>
                <td>Cinciniati Bengals</td>
            </tr>
            <tr>
                <td>Josh Allen</td>
                <td>Quarterback</td>
                <td>6ft 5</td>
                <td>27</td>
                <td>234</td>
                <td>Buffallo Bills</td>
            </tr>
            <tr>
                <td>T.J. Watt</td>
                <td>linebacker</td>
                <td>6ft 4</td>
                <td>28</td>
                <td>251</td>
                <td>Pittsburgh Steelers</td>
            </tr>
            <tr>
                <td>Myles Garrett</td>
                <td>Defensive End</td>
                <td>6ft 4</td>
                <td>27</td>
                <td>271</td>
                <td>Cleveland Browns</td>
            </tr>
            <tr>
                <td>Nick Chubb</td>
                <td>Running Back</td>
                <td>5ft 11</td>
                <td>27</td>
                <td>227</td>
                <td>Cleveland Browns</td>
            </tr>
            <tr>
                <td>Derrick Henry</td>
                <td>Running Back</td>
                <td>6ft 3</td>
                <td>29</td>
                <td>247</td>
                <td>Tennessee Titans</td>
            </tr>
            <tr>
                <td>Sauce Gardner</td>
                <td>Cornerback</td>
                <td>6ft 3</td>
                <td>22</td>
                <td>201</td>
                <td>New York Jets</td>
            </tr>
        </tbody>
    </table>
</body>

<!-- Script is used to embed executable code -->
<script>
    $("#demo").DataTable();
</script>

Player Position Height Age Weight Team
Patrick Mahomes Quarterback 6ft 2 27 225 Kansas City Chiefs
Tyreek Hill Wide Reciever 5ft 10 29 185 Miami Dolphins
Jaylen Waddle Wide Reciever 5ft 10 24 185 Miami Dolphins
Ja'Marr Chase Wide Reciever 6ft 0 23 201 Cinciniati Bengals
Joe Burrow Quarterback 6ft 4 26 216 Cinciniati Bengals
Josh Allen Quarterback 6ft 5 27 234 Buffallo Bills
T.J. Watt linebacker 6ft 4 28 251 Pittsburgh Steelers
Myles Garrett Defensive End 6ft 4 27 271 Cleveland Browns
Nick Chubb Running Back 5ft 11 27 227 Cleveland Browns
Derrick Henry Running Back 6ft 3 29 247 Tennessee Titans
Sauce Gardner Cornerback 6ft 3 22 201 New York Jets

Describe a benefit of using markdown tables

A benefit of using markdown tables is that it is very easy to show data that would be organized in tables, such as statsitics and other facts that can be shown such as the table above.

Try to Style the HTML table using w3schools.

In W3 schools styles HTML Tables in zebra stripes W3schools

Describe the difference between HTML and JavaScript.

The Difference between HTML and Javascript is that HTML gives the basic structure and meaning for web content whereas javascript is more advanced of a programming langauge

Describe a benefit of a table that uses JavaScript.

A beneift of a table that uses JavaScript includes that it is more advanced and can have more features as well as style becuase javascript is a more advanaced programming langauge than HTML.

Review of Week 2 Hacks

  • Learned about how to use HTML Tables with Javascript to show information and statsitics
  • Learned how to add an entire column to Javascript Query Tables
  • Learned how to Style HTML Tables
  • Learned the difference between HTML and Javascripot
  • Learned about the benefits of using a tables with Javascript that is being used.

Basic Java Code

Lab Notebook Hacks Week 1: IPYNB Table, Code


a = 1
b = 1;
if (a === b) {
    // JavaScript also uses curly braces to establish code block
    console.log("A equals B");
}

  Input In [3]
    if (a === b) {
            ^
SyntaxError: invalid syntax
FileSystem.out.println(1);
---------------------------------------------------------------------------

NameError                                 Traceback (most recent call last)

/home/shivansh/APCSA/realone/shivansh/_notebooks/2023-08-21-labnotebook.ipynb Cell 16 in <cell line: 1>()
----> <a href='vscode-notebook-cell://wsl%2Bubuntu/home/shivansh/APCSA/realone/shivansh/_notebooks/2023-08-21-labnotebook.ipynb#X24sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0'>1</a> FileSystem.out.println(1)


NameError: name 'FileSystem' is not defined