Welcome to APCSA

  1. Lesson 06 - User Input


    Slides

    Classwork

    Homework

  2. Lesson 05 - Casting


    Slides

    Classwork

    Homework

  3. Lesson 04 - Expressions and Assignment Statements


    Slides

    Classwork

  4. Lesson 03 - Data Types and Varialbes


    Slides

  5. Lesson 02 - Intro to Java


    Slides

  6. Lesson 01 - Git


    GitHub

    Read the Git and GitHub documentation provided in the Tools section.

    Git Commands: When to Use Them

    git clone

    When to use:
    Use this the first time you want to copy a remote repository (e.g., from GitHub) to your computer.

    Command:

    git clone <repository_ssh_url>

    Tip: Run this only once per project. After that, use git pull to update your local copy.

    git pull

    When to use: Use this to bring in the latest changes from the remote repository to your local repository.

    Command:

    git pull

    Tip: Always run this before starting new work to make sure your files are up to date.

    git add

    When to use: Use this to stage (mark) new or modified files that you want to include in the next commit.

    Command: For one file git add <file_name> For all changes git add .

    git commit

    When to use: Use this after git add to save a snapshot of your staged changes in the local repository.

    Command:

    git commit -am "Describe the change you made"

    Tip: Write clear and meaningful commit messages so you and others understand the change.

    git push

    When to use: To send your committed changes from your computer to the remote repository (e.g., GitHub).

    Command:

    git push

    Typical Workflow

    1. git pull: get the latest updates.

    2. Edit your code/files.

    3. git add: if new files have been added or to stage your changes.

    4. git commit -am "message": save your changes locally.

    5. git push: upload your changes to GitHub.

  7. HW 07 - Scanner


    DUE DATE:

    Go inside the folder homework, and create a subfolder 09_15_snooze. Inside this folder, you will write the following java file:

    NoonSnooze.java: This program should ask the user for a number that represents the number of minutes, snooze, that have elapsed since 12:00 pm (noon) and prints the resulting time. Assume a 12-hour clock (with 'am' and 'pm'). You must not use loops. If the snooze value is negative, print a warning message: "No negative values are allowed".

    Examples:

    If the user input is 50, the output should be 12:50 pm

    If the user input is 100, the output should be 1:40 pm

    If the user input is 721, the output should be 12:01 am

    If the user input is 11111, the output should be 5:11 am

    If the user input is -10, the output should be No negative values are allowed

  8. HW 06 - Practice Variables and Expressions


    DUE DATE:

    Go inside the folder homework, and create a folder 09_12_practice. Inside this folder, you will write the following programs:

    1. Write a Java program (Fractions.java). In this program you will initialize 4 integers that represent each part of two fractions, namely the numerator and denominator of the first fraction and the numerator and denominator of the second fraction. Your program should add the two fractions and print out the result.

    For example, a sample program run might look like this:

      The numerator of the first fraction is 1
      The denominator of the first fraction is 2
      The numerator of the second fraction is 2
      The denominator of the second fraction is 5
      The sum of 1/2 + 2/5 = 9/10
    
    1. Write a Java program (WorkShift.java). A doctor works 20 hours, 42 minutes, and 16 seconds in one shift at a hospital. Convert the total shift time into seconds and display that information.

    NOTE: You must use at least ONE compound operator (+=, -=, *=, /=, %=) to complete this program.

    Quiz Reminder

    The Summer Assignment Quiz will be on Tuesday, September 16th

  9. HW 05 - Data Types and Variables


    DUE DATE:

    Data Types and Variables

    Directions: Create a new folder named 09_10_variables inside your homework directory in your assignments repository: .../APCSA1/apcsa-assignments-fall-YourUsername/homework/09_10_variables

    Inside this folder, write the following programs:

    1. Write a Java program (Temperature.java) to convert temperature from Fahrenheit to Celsius degrees. You must use variables.

    Output:

    50.0 degrees Fahrenheit is equal to 10.0 Celsius

    1. Write a Java program (Calculator.java) that calculates the sum of two numbers (int or double). You must use variables.

    Output:

    10 + 12 = 22

    1. Create a file TrickyCalc.java and copy the following code inside. Run the program. Create a file answers.txt or answers.md and respond to the following questions:
    • What do you notice about the mySum value?
    • What is the value of checkResult, and why do we get that result?
    public class TrickyCalc{
       public static void main(String[] args){
           double mySum = 0.1 + 0.1 + 0.1;
           double tmp = 0.3;
           boolean checkResult = mySum == tmp;
    
           System.out.println("0.1 + 0.1 + 0.1 = " + mySum);
           System.out.println(mySum + " == " + tmp + " is " + checkResult);
       }
    }
    
    1. Don’t forget to add your new files to Git, then commit and push your changes. After that, go to GitHub and verify that your files are there. I will not accept any excuses tomorrow if your homework is missing.

    2. Double check that your files are organized like this in your repo:

    apcsa-assignments-YourUsername
      classwork
        09_09_hello_world
          HelloWorld.java
      homework
        09_09_welcome
          Welcome.java
        09_10_variables
          Temperature.java
          Calculator.java
          TrickyCalc.java
          answers.txt or answers.md
    

  10. HW 04 - Git commands practice


    DUE DATE:

    The objective of this homework is to create a java file, add it, commit and push to a remote repository.

    1. In your local machine at home, go to the folder where your assignments repo was cloned ...../APCSA1/apcsa-assignments-fall-YourUsername/, execute git pull and create a folder homework.
    2. Create a folder 09_09_welcome inside the homework folder.
    3. Write a java file Welcome.java (this should be the path ...../APCSA1/apcsa-assignments-fall-YourUsername/homework/09_09_welcome/Welcome.java). In this program, you should introduce yourself. Print two lines to the console using the System.out.println() method.

    In the first line, state your name, and in the second line state your favorite hobby.

    Your output should be in the following form:

    My name is ...
    My favorite hobby is ...
    
    1. Run git status. What does it show?

    2. To add the new file to the repository, run the following command from the root (top-level, ...../APCSA1/apcsa-assignments-fall-YourUsername/) of your repo, not from inside the homework folder:

      git add homework/09_09_welcome/Welcome.java

    3. Run git status again. What does it show this time?

    4. Commit and push the file to your repo.

    5. Go to GitHub, Welcome.java should be there.

    6. Tomorrow, we will pull the changes using the lab machines.

  11. HW 03 - Git


    DUE DATE:

    1. Set up SSH
      Configure your home computer to connect to GitHub using SSH, if you have not done that already.

    2. Accept the Assignments Repository

      • If you haven’t already, accept the assignments repository using this link.
      • After accepting, a repository will be created under your GitHub account.
      • If you run into any issues, contact me.
    3. Clone the Assignments Repository

      • Open your GitHub assignments repository for this class.
      • Click the green Code button, select SSH, and copy the link provided (it will look like git@...).
      • Create a folder named APCSA1 anywhere on your computer.
      • Open your terminal, navigate inside the APCSA1 folder, and run:
        git clone PASTE_THE_LINK_YOU_COPIED_FROM_GITHUB

    Quiz Reminder

    The Summer Assignment Quiz will be on Tuesday, September 16th.

  12. HW 02 - Summer Assignment, Piazza, Git


    DUE DATE:

    Summer Assignment

    1. Follow the next steps to share your CodingBat Summer work with me.
    • Log in to your CodingBat account.
    • Click on prefs
    • Teacher Share section: type the teacher's email jnovillo@stuy.edu
    • Click on Share
    • Update the Memo section: type YourPeriod_YourLastName_YourFirstName (no spaces) like this 1_smith_peter
    • Click on Update Memo
    1. Submit the complete Java program that was assigned (Google Classroom).

    Piazza

    1. Post a question or comment about the summer assignment. Feel free to reply to peer's comment/question to generate a productive discussion.

    GitHub

    1. Set up Git and SSH keys on your home computer and practice using Git commands. If you have any questions, post them on Piazza, and I encourage everyone to help your peers by answering those questions.

  13. HW 01 - Forms


    DUE DATE:

    Complete the following forms:

  14. CW 04 - Scanner


    DUE DATE:

    Save your file here: .../APCSA1/apcsa-assignments-fall-YourUsername/classwork/09_15_scanner/NightOut.java

    Follow these directions to write your NightOut.java program:

    You and a friend are going out for the night. You have decided to treat your friend, so you’re paying for the whole night. However, since you have a fixed amount of money to spend on fun things, you need to track how much the outing will cost so you can update your budget.

    Write a program to help yourself estimate what the total cost of the night will be. Your program will estimate the cost by taking the cost of the activities for one person and estimating how much it will cost for two people.

    Here’s what you know about your activities:

    Dinner - you know you typically get cheap dinners, so you expect that your friend’s dinner will be twice as expensive as yours

    Laser Tag - since laser tag is charged per person, you and your friend will cost the same

    Ice cream - you like the triple scoop, but your friend likes a single scoop. Your friend’s ice cream will cost 1/3 as much as yours.

    Your program should ask how much YOUR dinner cost, how much laser tag costs per person, and how much YOUR ice cream costs. It should then compute how much your friend’s costs will be based on the information above. Be sure your program takes the input in this exact order. Then print how much dinner will cost (for both of you), how much laser tag will cost (for both of you), and how much the ice cream will cost (for both of you). Then print the grand total for the evening.

    Your output should look something like this:

    How much does dinner usually cost? 
    
    12.63
    
    How much is laser tag for one person? 
    
    17.50
    
    How much does a triple scoop cost? 
    
    27.00
    
    Dinner: $37.89
    
    Laser Tag: $35.0  
    
    Ice cream: $36.0
    
    Grand Total: $108.89
    

  15. CW 03 - Casting


    DUE DATE:

    Create a java file Casting.java and implement a method that:

    • Receives 2 integers
    • Divides the two ints
    • Prints the result

    The trick here is that we want the division of the two ints to result in a double! Casting values to doubles will be necessary to solve this exercise. Here is an example:

    x = 3
    
    y = 4
    
    Output => 0.75
    

    Save your file here: .../APCSA1/apcsa-assignments-YourUsername/classwork/09_12_casting/Casting.java

  16. CW 02 - Expressions


    DUE DATE:

    Indicate the value and type of each of the following expressions. If the expression does not compile or causes a runtime exception, put an X.

    You do not have to submit this work, but do it on your notebook so you can review it at any time.

    Expressions
    
    2 + 5
    
    8 / 10 * 1.5
    
    12 % 7
    
    2 + 3 * 4
    
    2 + 3.0 * 4
    
    1 / 1 / 0
    
    1.0 / 1 / 0
    
    “Happy” + “Face”
    
    “8+2” + “5”
    
    “10” + 8 + 12
    
    2 + 4 + "5" + 6
     
    27 % 4
    

  17. CW 01 - Hello World and Git


    DUE DATE:

    The objective of this exercise is to create a java file, add it, commit and push to a remote repository.

    1. In your local machine, go to the folder where your assignments repo was cloned ...../APCSA1/apcsa-assignments-fall-YourUsername/, execute git pull and create a folder classwork.

    2. Create a folder 09_09_hello_world inside the classwork folder.

    3. Write a java file HelloWorld.java that prints the message "Hello World!".

    4. Run git status. What does it show?

    5. To add the new file to the repository, run the following command from the root (top-level, ...../APCSA1/apcsa-assignments-fall-YourUsername/) of your repo, not from inside the classwork folder:

      git add classwork/09_09_hello_world/HelloWorld.java

    6. Run git status again. What does it show this time?

    7. Commit and push the file to your repo.

    8. Go to GitHub, HelloWorld.java should be there.