diff --git a/_notebooks/2023-04-27-FRQExtra.ipynb b/_notebooks/2023-04-27-FRQExtra.ipynb index 5ceba41..eb445c7 100644 --- a/_notebooks/2023-04-27-FRQExtra.ipynb +++ b/_notebooks/2023-04-27-FRQExtra.ipynb @@ -109,17 +109,6 @@ "In order to count how many times the isValid method returned false, a new integer counter field would need to be created for the CheckDigit class. Every time, either in the else statement in the isValid method, or whenever the isValid method returns false within another class from method, this field should be incremented by 1." ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "vscode": { - "languageId": "java" - } - }, - "outputs": [], - "source": [] - }, { "attachments": {}, "cell_type": "markdown", @@ -176,6 +165,244 @@ " return true;\n", "}" ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 2D array FRQ" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "vscode": { + "languageId": "java" + } + }, + "outputs": [], + "source": [ + "public static boolean isNonZeroRow(int[][] array2D, int r)\n", + "{\n", + " for(int v : array2D[r])\n", + " if(v == 0)\n", + " return false;\n", + "\n", + " return true;\n", + "}" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Arrays ArrayLists FRQ\n", + "## Question 1" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "vscode": { + "languageId": "java" + } + }, + "outputs": [], + "source": [ + "public void addMembers(String[] names, int gradYear)\n", + "{\n", + " for(String name : names)\n", + " memberList.add(new MemberInfo(name, gradYear, true));\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "java" + } + }, + "outputs": [], + "source": [ + "public ArrayList removeMembers(int year)\n", + "{\n", + " ArrayList goodStanding = new ArrayList();\t\n", + "\n", + " int i = 0;\n", + " while(i < memberList.size())\n", + " {\n", + " if(memberList.get(i).getGradYear() <= year)\n", + " {\n", + " MemberInfo removed = memberList.remove(i);\n", + " if(removed.inGoodStanding())\n", + " goodStanding.add(removed);\n", + " }\n", + " else\n", + " i++;\n", + " }\n", + " \n", + " return goodStanding;\n", + "}" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Question 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "java" + } + }, + "outputs": [], + "source": [ + "public static int[] getCubeTosses(NumberCube cube, int numTosses)\n", + "{\n", + " int[] tosses = new int[numTosses];\n", + "\n", + " for (int i = 0; i < tosses.length; i++)\n", + " tosses[i] = cube.toss();\n", + "\n", + " return tosses;\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "vscode": { + "languageId": "java" + } + }, + "outputs": [], + "source": [ + "public static int getLongestRun(int[] values)\n", + "{\n", + " int lengthOfLongestRun = 1;\n", + " int startOfLongestRun = -1;\n", + "\n", + " int lengthOfCurrentRun = 1;\n", + "\n", + " for (int i = values.length - 2; i >= 0; i--)\n", + " {\n", + " if (values[i] == values[i + 1])\n", + " {\n", + " lengthOfCurrentRun++;\n", + " if(lengthOfCurrentRun > lengthOfLongestRun)\n", + " {\n", + " lengthOfLongestRun = lengthOfCurrentRun;\n", + " startOfLongestRun = i;\n", + " }\n", + " }\n", + " else\n", + " lengthOfCurrentRun = 0;\n", + " }\n", + "\n", + " return startOfLongestRun;\n", + "}" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Class FRQ\n", + "## Question 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "java" + } + }, + "outputs": [], + "source": [ + "public class MultPractice implements StudyPractice\n", + "{\n", + " private final int first;\n", + " private int second;\n", + "\n", + " public MultPractice(int f, int s)\n", + " {\n", + " first = f;\n", + " second = s;\n", + " }\n", + "\n", + " public String getProblem()\n", + " {\n", + " return first + \" TIMES \" + second;\n", + " }\n", + "\n", + " public void nextProblem()\n", + " {\n", + " second++;\n", + " }\n", + "}" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Combined Table FRQ" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "java" + } + }, + "outputs": [], + "source": [ + "public class CombinedTable\n", + "{\n", + " private SingleTable t1, t2;\n", + "\n", + " public CombinedTable(SingleTable t1, SingleTable t2)\n", + " {\n", + " this.t1 = t1;\n", + " this.t2 = t2;\n", + " }\n", + " \n", + " public boolean canSeat(int people)\n", + " {\n", + " int seats = t1.getNumSeats() + t2.getNumSeats() - 2;\n", + " return seats <= people;\n", + " }\n", + " \n", + " public double getDesirability()\n", + " {\n", + " double averageView = (t1.getViewQuality() + t2.getViewQuality()) / 2;\n", + "\n", + " if(t1.getHeight() == t2.getHeight())\n", + " return averageView;\n", + " else\n", + " return averageView - 10;\n", + " }\n", + "}" + ] } ], "metadata": {