How to access each digit in an int in Java
1 2 3 4 5 6 7 |
int n ; // some integer while ( n > 0){ int digit = n % 10 ; //ones place digit print(digit) ; n = n / 10 ; // now the ones place by int division } |
How to access each digit in an int in Java
1 2 3 4 5 6 7 |
int n ; // some integer while ( n > 0){ int digit = n % 10 ; //ones place digit print(digit) ; n = n / 10 ; // now the ones place by int division } |
ArrayFun3 - Please call your class that , exactly. Yes, you will lose a point for not following this simple specification.
int[] removeZeroes(int [] nums)
Description: This method returns a version of nums in which all occurrences of 0 , zero, are removed
Method Call | return value/output |
noZeroes( { 3 , 4, 0, 1} ) | { 3, 4, 1} |
noZeroes( { 0, 5 , 0, 0, 9, 0, 1 , 11} ) | { 5,9,1,11} |
String[] removeNulls(String[] strs)
Description: This method returns a version of strsin which all null values are removed. Note:
int[] digitsToArray(int n)
@precondition n > 9
Description: This method takes each digit in the integer n and stores it in an array in reverse order, as shown below. First, make sure you understand the code here. , which btw, testers had to figure out , on the fly, in a previous AP A test.
int[] removeLeadingZeroes(int[] nums)
@precondition nums.length >=2
Description: This method returns an array in which all elements that meet the 2 criteria below are removed.
int[] doubleUp( int [] nums, int val)
@precondition nums.length >=2
Description: This method returns a version of nums –with all occurrences of val duplicated.
Method Call | return value/output |
doubleUp( { 3 , 4, 0, 1} , 4 ) | { 3, 4 , 4, 0, 1} |
doubleUp( { 1, 3 , 1, 5 , 3, 3} , 3 ) | {1 , 3, 3 , 1, 5 , 3, 3, 3, 3 } |
Similar problems on codingbat
In addition to the required Unit 2 Creative Task, if you want some extra credit, you can do the following assignment:
Research how groups work in CMU ( see the docs)
Write a program that
You can write this in one of empty creative a tasks.
For this creative task,
This is a 10 Point assignment:
To get 9 points:
To get the 10th point,
Research how groups work in CMU ( see the docs),
Copy and Paste the HTML file below into its own file
Updated Version:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap 4.6 --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous"> <!-- jQuery --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js" crossorigin="anonymous"></script> <title>Hello, world!</title> </head> <body> <div class="container"> <h1>Hello, world!</h1> </div> <!-- .container end--> </body> <!-- Bootstrap .bundle includes popper --> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script> </html> |
Version 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <!-- jQuery --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js" crossorigin="anonymous"></script> <title>Hello, world!</title> </head> <body> <h1>Hello, world!</h1> <!-- Optional JavaScript --> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> </body> </html> |
Quarter 4 project
Prior iterations : https://mrmonline.org/supa-2020/ , https://mrmonline.org/web-design-programming-18-19/
Templates
Bootstrap
Vim
Getting Starting with Solving Mazes
Soon we will be doing more challenging Mazes here : https://mrmonline.org/maze-activities-1/
The Economy
Create a maze along the lines here https://mrmonline.org/maze-activities-1/ , https://mrmonline.org/mazes-3/
Your maze should be able to be solved by 1 loop. You are allowed to add a few lines after the loop to “clean up” the solution if you want but the bulk of the maze should be solvable using a single while loop.
Submit both the map and your solution.
Let’s write a program for something like PowerSchool that helps organize a seating chart for students. There is a tester file at the page’s bottom.
First class : Student , from https://mrmonline.org/student-class/
Class SeatingChart
This class mainly manages a 2-d array of student objects. Note: an empty seat in the chart will be designated by a null value.
1 2 3 4 5 6 |
private Student[][] chart ; // rows and columns for where kids are private String rosterName; //name of this roster private String teacherName; private int period ; //which period is this chart associated public static final int DEFAULT_ROWS = 10; public static final int DEFAULT_COLS = 10; |
public String getTeacherName() // returns teacherName
public String getRosterrName() // returns rosterName
public int getPeriod() // returns period
public int countEmptySeats() ; //returns the number of empty seats. As noted earlier, an empty seat is represented by a null value in the 2-d array of student s
Student[][] getStudentChart() @returns chart
public int[] indexOf(Student stu); returns a 2 element array representing the row and column position of stu in chart ; [-1 , -1] should be returned if stu is not in chart
public boolean setSeat(int row, int col, Student stu) - places Student Stu at that row and column . This can only be done if there is no student in that location. If a student already inhabits that row and column then the method should return false and not make any changes to chart .
public void swap(Student s1, Student s2) // this swaps the locations of s1 and s2
public Student getStudent(int row, int col) returns the student at the given row and col ; or null if the seat is empty
public void removeStudentAt(int row, int col) sets value of object at row and col to null
public boolean equals(SeatingChart other) // returns true if all aspects of other are equivalent to self.
public void colMajorForm() . This prints out the student chart in column major form. Examine the diagram below showing an example seating chart on the left and the printed output on the right.
public String toString(); //follow the conventions we have been using. When you print out the chart , let’s show
"E!" t o indicate an empty seat; for seats with students, just display their name.
public Student oldest() // returns the student object with the greatest age
Extra credit
public void randomize() // this randomizes the chart. Please be prepared to meet with me to discuss your code. (You cannot use a library to do all the work, if such a library even exists)
SeatingChartTesterv2.java :