Blackjack Codingbat Solution

 

For further help with Coding Bat (Java), please check out my books. I am also available for tutoring.

Edit: After receiving the great feedback, I have tried to make my code better. The new version can be seen here: Simple Blackjack game in console (update) This is one of my first finished projects. CodingBat External Url. CodingBat codingBat Score at least Must. Blackjack Project Handout.pdf Blackjack Project Handout.pdf. Score at least Must score at.

The Logic-2 section of CodingBat contains just nine exercises. Yet, there are slightly more challenging than any of the pervious exercises, which means that you may have to spend more time on them, compared to, say, String-1. “makeBricks” is a favorite of mine, not just because some of the solutions floating around on the Internet are nothing but comical. It’s a similar story with “makeChocolate”.

All solutions were successfully tested on 10 February 2013.

makeBricks:

I split the line to make the expression more readable.

loneSum:

luckySum:

noTeenSum:

roundSum:

closeFar:

Codingbat

blackjack:

evenlySpaced:

makeChocolate:

The parentheses in the return statements are not necessary, but they allow you to parse the statements more quickly since you can immediately identify all parts of the ternary operator.

Codingbat blackjack solution

For further help with Coding Bat (Java), please check out my books. I am also available for tutoring.


N

Date

Topic

File/Worksheets

Due Date

Drop Off Folder

Notes to read / Homework

15/09Inroduction. Gr 11 reviewJava Review Cheat Sheet
9.0901_DMOJRead Java Review Cheat Sheet Section 1 - 19
DMOJ.ca questions
Question 1: CCC '12 J2 - Sounds fishy!
Question 2: CCCHK '08 J2 - Lucky Number
29/09Gr 11 review
13.0901_DMOJRead Java Review Cheat Sheet Section 21-26
DMOJ.ca questions
Solve 3.5 questions: Victoria Park Programming Contest for Beginners
311/09Pseudocode. JETS. Flow charts.Sorting algoriths.pseudocode-in-exams.pdf
Approved_Pseudocode_Notation_Sheet.pdf
JETS.pdf
Homework: Textbook. Chapter 4. pp.174-183.
ICS4U_Arrays_SortingExercise_2019.doc
4,5,623-19/09 Pseudocode. Flow charts. Review Java Grade 11.DynamicArrays_ArrayLists.docHomework: Textbook. Chapter 4. All pages.
723/09Array Lists. Collections. Pseudocode. Big O notation.ICS4U_Chapter4_Highlights.docx
Homework: Textbook. Chapter 4. pp.174-183.
Homework23_09.docx
825/09 Pseudocode. 2D_array_GanttChart_IB_ICS4U.docx
Homework: Textbook. Chapter 4. All.
Homework_PseudoCodePractice_25_09.docx
927/09Review OOPOOP_01_Objects_Constructors.doc
OOP_02_UML_Encapsulation.doc
OOP_03_Overloading_static_toString.doc
OOP_04_Inheritance.doc
OOP_05_Static_Methods_Examples.doc
OOP_06_definitions_Polymorphism.doc
Homework:
Textbook. Chapter D2. pp.312-318.
101/10 Test 1 Part A (club fair)
Homework: Textbook. 312-318.
113/10 Test 1 Part B

127/10UML diagrams, Inheritance, Aggregation, and DependencyUML diagrams_practice.docx
Homework:
UML diagrams_practice.docx
Text book: 294-308
139/10GUI reviewA folder GUI/Layouts is posted in the pickUp areaHomework:
Create a JFrame and 2 JPanels. One panel should be intro/menu pannel; second panel should have GUI components. Use Layouts to place JTextFields, JButtons, JLabels, and so on.
1315/10Actions: Action Listeners, Mouse Listeners, Key ListenersHomework:Add actions(button click, mouse listener, key listener, and so on) to your Frames/Panels. Make sure you have several GUI components - frames should look like your IA project.
14-19Oct 17, 21, 23, 25, 29, 31Test analysis, GUI ProjectGUI_Project_2020.docxHomework:GUI project
21Nov 5GUI Project analysis, DatabasesDatabases for beginners.pdfHomework:Databases. COntinue to work on IA project
227/11JTable, OO test practiceExample PhilosophersJTable.java in the pick up folder
JTable_expanation_example.pdf
Homework:Homework_practicePaper2.pdf
Homework_practicePaper2_2.pdf
2311/11Databases, ODBC driversDatabaseWithJTable.java in the pick up folder
DatabasesSQL.pdf
SQLITE_driver_ECLIPSE.docx
Homework: Create a dabase. Access it from Java application.
Prepare for the test 2 OOP.
2413/11Test 2 OOP
15/11PA day
2519/11System Fundamentals 1.1.1-1.1.71_1_1_7_SystemFundamentals.pptx - pick up folder
Topic 1 Systems in organisationsNotes.docx - pick up folder
Homework:
Textbook: pages 1-12
Online quiz
Video on youtube (all or from 10.23 to 26:40 )
2621/11System Fundamentals 1.1.8-1.1.14; 1.2.11_8_1_14.pptx - pick up folder
Topic 1 Systems in organisationsNotes.docx - continue pick up folder
Homework:
Textbook: pages 13-23
Online quiz
System Fundamentals - Part 3 the rest
System Fundamentals - Part 4
System Fundamentals - Part 1
System Fundamentals - Part 2
2725/11Quiz 1. Test 2 Analysis. TestAnalysis_OOP_test2.pptx - pick up folder
Homework:
Textbook: review pages 1-41
Youtube videos listed for the previous class(21/11).
2827/11System Fundamentals 1.2.1 - 1.2.8 Was coverd on November 23rd. insteaf of 1.1.8-1.1.14
System Fundamentals 1.2.9 - 1.2.16
1_2_1_1_2_8.pptx - pick up folder
1_2_9_1_2_16.pptx - pick up folder
Homework:
Textbook: pages 41-57
Youtube videos listed for the previous class(21/11).
2929/11Computer Organization 2.1.1-2.1.32_1_1__2_1_3.pptx - pick up folder
Homework:
Textbook: pages 61-68
Computer Organization - Part 1
Computer Organization - Part 2
303/12Computer Organization 2.1.4-2.1.102_1_4__2_1_10.pptx - pick up folder
Homework:
Textbook: pages 68-102
Computer Organization - Part 1
Computer Organization - Part 2
315/12Network 3.1.1-3.1.43_1_1_3_1_4.pptx - pick up folder
Homework:
Textbook: pages 124-145
Networks - Part 1
Networks - Part 2
329/12Network 3.1.5-3.1.113_1_5_3_1_11.pptx - pick up folder
Homework:
Textbook: pages 148-155
Networks - Part 3
33,34,3513,17,19 /12Computer Organization 2.1.9-2.1.14. Binary numbers, Logic Gates, Truth Tables, Logic EquationsBooklet
Homework:
Textbook: pages 86-123
Booklet: pages 1-48
367/01Network 3.1.9-3.1.10, 3.1.12-3.1.17(on your own)3_1_9__3_1_16___4_2_8.pptx - pick up folder
Homework:
Textbook: pages 152-171
379/01Quiz on Topic 3 - Networks; Stacks and Queues5_1_4__5_1_8.pptx - pick up folder
Homework:
HL Textbook: pages 7-22, and 44-45.
Homework I: Programming problem to submit: bracket balancing using stacks.To Submit: Java code and pseudocode
Balancing brackets_HomeworkResources.docx
Homework II: infix <--> prefix<--> postfix. Handout distributed in class. Additional examples and explanations are here:
InfixPostFix_Handout_withHomework.docx and solutions
PostFixPreFix_Examples.docx
3913/01Recursion.
Homework:
I. HL Textbook: pages 5-6, Handout 'Recursion 1' in the pick up folder
II: Write a java code Codingbat.com website. any 3 from Recursion 1 section, any 3 from Recursion 2 section.
https://codingbat.com/java
4015/01Recursion 2. Recursion and Graphics. In the pick up folder:
Recursion 2.doc
Homework:
Programs: Tree. Tower of Hanoi - at the end of 'Recursion 2' document.
4117/01Recursion for IA. Traicing practice. Merge sort.In the pick up folder:
SimpleRecursionTraicingPractice.docx
MergeSort.ppt
Homework:
Programs: Write merge sort program. Pass an array populated with random numbers, sort if with merge sort and display.
4221/01No Test. Stay home and study.
4329/01Marks review day. Word scrambler with recursion Homework:
Write word scrambler program. Use recursion. You can try it on DMOJ.ca
https://dmoj.ca/problem/dwite09c1p2
or
https://dmoj.ca/problem/ics4p1
4331/01Linked Lists. Doubly Linked Lists. Trees. 5_1_12_5_1_15.pptx

Homework: textbook pp.23-29- review Queues and Stacks
textbook pp.30-38
443/02Binary Trees. Bianry Search Trees. 5_1_16__5_1_17.pptx

Homework: textbook pp.39- 55
455/02BST implementation. ADT: advantages/disadvantages. Chapter 5 review. 5_1_18__5_1_20.pptx

Homework: textbook - End of chapter examples pp.56- 66
Update BST we created in class. Add
1) removing a node which has a particular data( search for the node first).
2) find minimum vlaue of the tree
467/02Catch Up day. IA

4711/02Test Topic 4 and 5

48Feb.13 Topic 6 and Topic 7. 6_1_1__6_1_3.pptx
6_1_4__6_1_8.pptx
7_1_1__7_1_8.pptx

Power-point files are in the pick-up folder.
49Feb.19 Topic 7 Cont. Case study case_study_2020.pdf

Power-point files are in the pick-up folder.
Read 2020 case study. Pick one term from the list of terms of the 2020 case study. Submit the definition and explain it to the class.

2018-2019 year
Codingbat

Codingbat Blackjack Solution

1-76, 10, 12, 14, 18, 20, 24/09Inroduction. Gr 11 reviewJava Review Cheat Sheet
826/09Test 1
928/09Pseudocode. JETS. Flow charts.pseudocode-in-exams.pdf
Approved_Pseudocode_Notation_Sheet.pdf
JETS.pdf
Homework: Textbook. Chapter 4. pp.174-195.
102/10Sorting algoriths.Flow chartsSortingAlgorithms.docx
Methods_ArrayTraicingPractice.docx
Homework: Textbook. Chapter 4. pp.196-230.
114/10Review OOP 1CardMethods.txt
Homework:
(Same as last class)Methods_ArrayTraicingPractice.docx
(Same as last class)Textbook. Chapter 4. pp.196-230.
(new)Start working on Black Jack Assignment
1210/10Review OOP 2OOP_01_Objects_Constructors.doc
OOP_02_UML_Encapsulation.doc
OOP_03_Overloading_static_toString.doc
OOP_04_Inheritance.doc
OOP_05_Static_Methods_Examples.doc
OOP_06_definitions_Polymorphism.doc
Homework:
Textbook. Chapter D2. pp.312-318.
Continue working on Black Jack Assignment
1312/10CollectionsCollectionPseudocode_Practice.docx
Homework:
Textbook. pp.218-219 and 256-289.
PseudoCode Homework Practice
1416/10Black Jack ProjectBlack JackProject.doc
Homework:
Create at least 2 classes for the BlackJack project
1518/10UML diagrams, Inheritance, Aggregation, and DependencyUML diagrams_practice.docx
Homework:
Continue working on BlackJack project
Finish IA Part A: Planning. Due on October 22!!!!
Text book: 291-312
1622/10IA Part A: Planning due. Work Period. Black Jack Project.IA_Assessment_criteria.doc
A Planning_Sequence_and_CheckMarks.docx
Check next tab Gr12 IB Demo for word count and format guidelines.(table on the buttom of the page)
Homework:
Continue working on BlackJack project
Text book: 291-316
1724/10GUI review2 folders(02_Layouts, 03_MoreLayouts) and a file(01_GUI 1.doc) are posted in the pickUp areaHomework:
Create a Frame/Pannel similar to your IA
1826/10GUI eventsTest is moved to October 30 due to Robotics tripHomework:
Finish Black Jack which is due October 30st
Add a Button click event to your GUI exercise
1930/10Events: Mouse listenersHomework:
Continue working on your GUI project
202/11OOP TestHomework:
Continue working on your IA (GUI part)
216/11BlackJack analysisHomework:
Continue working on your IA (GUI part)
228/11Test 2 back. Events: Keyboard ListenerHomework:
Continue working on your IA (GUI part)
Link to ComboBox examples ( for Talia)
Link to example on how to add ImageIcon to a label ( for Manasha)
23-2412,14/11DatabasesHomework:
Continue working on your IA (GUI part + database part)
2520/11System Fundamentals 1.1.1-1.1.71_1_1_7_SystemFundamentals.pptx - pick up folder
Topic 1 Systems in organisationsNotes.docx - pick up folder
Homework:
Textbook: pages 1-12
Online quiz
Video on youtube (all or from 10.23 to 26:40 )
2622/11System Fundamentals 1.1.8-1.1.14; 1.2.11_8_1_14.pptx - pick up folder
Topic 1 Systems in organisationsNotes.docx - continue pick up folder
Homework:
Textbook: pages 13-23
Online quiz
System Fundamentals - Part 3 the rest
System Fundamentals - Part 4
System Fundamentals - Part 1
System Fundamentals - Part 2
2826/11System Fundamentals 1.2.1 - 1.2.8 Was coverd on November 23rd. insteaf of 1.1.8-1.1.14
System Fundamentals 1.2.9 - 1.2.16
1_2_1_1_2_8.pptx - pick up folder
1_2_9_1_2_16.pptx - pick up folder
Homework:
Textbook: pages 41-57
Youtube videos listed for the previous class(22/11).
2930/11Computer Organization 2.1.1-2.1.32_1_1__2_1_3.pptx - pick up folder
Homework:
Textbook: pages 61-68
Computer Organization - Part 1
Computer Organization - Part 2
303/12Computer Organization 2.1.4-2.1.102_1_4__2_1_10.pptx - pick up folder
Homework:
Textbook: pages 68-102
Computer Organization - Part 1
Computer Organization - Part 2
31,32,336,10,12 /12Computer Organization 2.1.9-2.1.14. Binary numbers, Logic Gates, Truth Tables, Logic EquationsBooklet
Homework:
Textbook: pages 86-123
Booklet: pages 1-48
3414/12Network 3.1.1-3.1.43_1_1_3_1_4.pptx - pick up folder
Homework:
Textbook: pages 124-145
Networks - Part 1
Networks - Part 2
3518/12Network 3.1.5-3.1.113_1_5_3_1_11.pptx - pick up folder
Homework:
Textbook: pages 148-155
Networks - Part 3
3620/12Network 3.1.9-3.1.10, 3.1.12-3.1.173_1_9__3_1_16___4_2_8.pptx - pick up folder
Homework:
Textbook: pages 152-171
378/01Quiz on Topic 3 - Networks; Stacks and Queues5_1_4__5_1_8.pptx - pick up folder
Homework:
HL Textbook: pages 7-22, and 44-45.
Homework I: Programming problem to submit: bracket balancing using stacks.To Submit: Java code and pseudocode
Balancing brackets_HomeworkResources.docx
Homework II: infix <--> prefix<--> postfix. Handout distributed in class. Additional examples and explanations are here:
InfixPostFix_Handout_withHomework.docx and solutions
PostFixPreFix_Examples.docx
3810/01Stacks and Queues implementation. Evaluation of postfix expressions
Homework:
I. HL Textbook: pages 23-29,
II: Write a java code to evaluate postfix expression. You can update my program that converts in-fix into post-fix (in the InfixPostFix_Handout.doc) by adding evaluation method.
III. 2D array practice
2D_arrayPractice_Homework.docx
3914/01Recursion.
Homework:
I. HL Textbook: pages 5-6, Handout 'Recursion 1' in the pick up folder
II: Write a java code Codingbat.com website. any 4 from Recursion 1 section, any 2 from Recursion 2 section.
https://codingbat.com/java
4016/01Recursion 2. Recursion and Graphics. In the pick up folder:
Recursion 2.doc
PracticeQuestion_RecursionInClass.doc
Homework:
Programs: Tree. Tower of Hanoi.
4118/01Linked List. Review for the test. Short day.Homework:
Programs: Tree. Tower of Hanoi.
4222/01Test. Recursion. Stacks. Queues.

434/02Linked Lists (Cont..) Doubly Linked Lists. Trees.

434/02Linked Lists (Cont..) Doubly Linked Lists. Trees. 5_1_12_5_1_15.pptx

446/02Binary Trees. Bianry Search Trees. 5_1_16__5_1_17.pptx

448/02BST implementation. ADT: advantages/disadvantages.

Update BST we created in class. Add removing a node which has a particular data( search for the node first).
45-49Feb.12,14, 18,20, and 22 Topic 6 and Topic 7.

Power-point files are in the pick-up folder.
5026/02Controls System. Case study.

Read CaseStudy2019.pdf
Prepare explanation/definition of one of the terms for case study.
5128/02Case study: Definitions.

Prepare one question for the case study discussion.
524/02Case study: Defintions. Alghorithms.

Learn about load balancing algoriths.
Find information about 'source IP hash'.
Read and analyze the article “London Ambulance CAD failure” https://erichmusick.com/writings/technology/1992-london-ambulance-cad-failure.html
Link to IA ListSolution

Blackjack Codingbat Solutions