Programming in Two Semesters: Using Python and Java

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

This highly accessible textbook teaches programming from first principles. In common with many programming courses, it uses Python as the introductory programming language before going on to use Java as the vehicle for more advanced programming concepts.

The first part, which teaches Python, covers fundamental programming concepts, such as data types and control structures and functions. It introduces more complex data types such as lists and dictionaries and also deals with file handling. It introduces object-oriented concepts and ends with a case study bringing together all the topics of the first semester.  The second part uses Java to teach advanced concepts and centres around object-oriented programming, teaching key object-oriented concepts such as inheritance and polymorphism.  The semester again ends with an advanced case study bringing together all the topics of the second semester.

Topics and features:

  • Assumes no prior knowledge, and makes the transition from Python to Java a smooth process
  • Features numerous exercises and also an illustrative case study for each language
Examines procedural and object-oriented methodologies, as well as design principles
  • Covers such advanced topics as interfaces and lambda expressions, exceptions and Collections
  • Includes a chapter on graphics programming in Python using Tkinter 
  • Introduces the latest Java technology for graphical interfaces, JavaFX
  • Explains design concepts using UML notation

Offering a gentle introduction to the field and assuming no prerequisite background, Programming in Two Semesters is the ideal companion to undergraduate modules in software development or programming.  In addition, it will serve as a strong primer for professionals looking to strengthen their knowledge of programming with these languages.

Author(s): Quentin Charatan, Aaron Kans
Series: Texts in Computer Science
Publisher: Springer
Year: 2022

Language: English
Pages: 664
City: Cham

Preface
Contents
Semester One: Python
1 Python: The First Step
1.1 Introduction
1.2 Software
1.3 Programming
1.4 Downloading and Installing the Interpreter
1.5 Your First Program
1.6 Adding Comments to a Program
1.7 Self-test Questions
1.8 Programming Exercises
2 Python: Building Blocks
2.1 Introduction
2.2 Output in Python
2.3 An Interactive Program
2.4 Variables and Types
2.5 Arithmetic Operators
2.6 Expressions in Python
2.7 More About Output
2.8 Input in Python
2.9 Formatting Strings
2.10 Type Casting
2.11 Escape Sequences
2.12 Self-test Questions
2.13 Programming Exercises
3 Python Control Structures: Selection
3.1 Introduction
3.2 Making Choices
3.3 The ‘if’ Statement
3.3.1 Comparison Operators
3.3.2 Multiple Instructions Within an ‘if’ Statement
3.4 The ‘if…else’ Statement
3.5 Logical Operators
3.6 Nested ‘if…else’ Statements
3.7 Self-test Questions
3.8 Programming Exercises
4 Python Control Structures: Iteration
4.1 Introduction
4.2 The ‘for’ Loop
4.2.1 Varying the Loop Counter
4.2.2 The Body of the Loop
4.2.3 Revisiting the Loop Counter
4.3 The ‘while’ Loop
4.4 The ‘break’ Statement
4.5 The ‘continue’ Statement
4.6 A Couple of Pitfalls
4.7 The ‘try … except’ Statement
4.8 Self-test Questions
4.9 Programming Exercises
5 Python: Functions and Modules
5.1 Introduction
5.2 Declaring and Defining Functions
5.3 Calling a Function
5.4 Function Input and Output
5.5 More Examples of Functions
5.6 Variable Scope
5.7 Global Variables: The Pitfalls
5.8 Using Functions in Menu-Driven Programs
5.9 Built-In Functions
5.10 String Functions
5.11 Modules
5.12 Self-test Questions
5.13 Programming Exercises
6 Python Collections: Lists and Tuples
6.1 Introduction
6.2 Creating Lists
6.3 Accessing List Elements
6.4 Passing Lists as Parameters
6.5 Returning a List from a Function
6.6 More List Functions
6.7 Queues and Stacks
6.8 Creating a List Using Comprehension
6.9 Tuples
6.10 Variable Length Parameter Lists
6.11 Self-test Questions
6.12 Programming Exercises
7 Python Collections: Dictionaries and Sets
7.1 Introduction
7.2 Dictionaries
7.3 Creating Dictionaries
7.4 More Dictionary Functions
7.5 Creating a Dictionary Using Comprehension
7.6 Keyworded Variable Length Parameter Lists
7.7 Sets
7.8 Creating a Set Using Comprehension
7.9 Self-test Questions
7.10 Programming Exercises
8 Object-Oriented Python: Part 1
8.1 Introduction
8.2 Classes and Objects
8.3 Properties
8.4 The Rectangle Class
8.5 Testing the Rectangle Class
8.6 The BankAccount Class
8.7 Collections of Objects
8.8 Designing and Implementing Classes in Python
8.9 Implementing the BankAccount Class
8.10 A Bank Application
8.11 Class Variables
8.12 The __str__ Method
8.13 Encapsulation
8.14 Self-test Questions
8.15 Programming Exercises
9 Object-Oriented Python: Part 2
9.1 Introduction
9.2 Defining Inheritance
9.3 Implementing Inheritance in Python
9.4 Extending the Rectangle Class
9.5 Method Overriding
9.6 Built-in Object Functions
9.7 Some Benefits of Object-Oriented Programming
9.8 Self-test Questions
9.9 Programming Exercises
10 Python: Working with Files
10.1 Introduction
10.2 Input and Output
10.3 Input and Output Devices
10.4 File Handling
10.4.1 Encoding
10.4.2 Access
10.5 Reading and Writing to Text Files
10.6 Exceptions Associated with File Handling
10.7 Practical Examples
10.7.1 Adding File Handling to the Waiting List Application
10.7.2 Adding File Handling to the Bank Application
10.8 Reading into a Buffer
10.9 Reading and Writing to Binary Files
10.10 Deleting and Renaming Files
10.11 Self-test Questions
10.12 Programming Exercises
11 Python Graphics with Tkinter
11.1 Introduction
11.2 Tkinter: An Overview
11.3 Your First Graphics Program
11.4 Configuring Components
11.5 An Interactive Graphics Application
11.6 Binding to Multiple Events
11.7 Keyboard Events
11.8 Other Common Events
11.9 More About Labels
11.10 More About the Pack Layout Manager
11.11 A Graphical User Interface (GUI) for the Rectangle Class
11.12 The Grid Layout Manager
11.13 The Canvas Widget
11.14 The Place Layout Manager
11.15 The Variable Class
11.16 Check Boxes and Radio Buttons
11.17 Themed Widgets (and Combo Boxes)
11.18 Self-test Questions
11.19 Programming Exercises
12 Python Case Study
12.1 Introduction
12.2 The Requirements Specification
12.3 The Design
12.4 Implementing the Payment Class
12.5 Implementing the PaymentList Class
12.6 Testing the PaymentList Class
12.7 Implementing the Tenant Class
12.8 Implementing the TenantList Class
12.9 Design of the GUI
12.10 Designing the Event-Handlers
12.11 Implementing the Hostelapplication Program
12.12 Testing the System
12.13 What Next?
12.14 Self-test Questions
12.15 Programming Exercises
Semester Two: Java
13 Java: Input, Output and Data Types
13.1 Introduction
13.2 Programming in Java
13.3 Integrated Development Environments (IDEs)
13.4 Your First Java Program
13.4.1 Analysis of the “Hello World” Program
13.4.2 Adding Comments to a Java Program
13.5 println Versus print
13.6 Variables in Java
13.7 Creating Constants
13.8 Expressions in Java
13.9 The FindCost Program
13.10 Input in Java: The Scanner Class
13.11 Self-test Questions
13.12 Programming Exercises
14 Java Control Structures
14.1 Introduction
14.2 Making Choices in Java
14.2.1 The ‘if’ Statement
14.2.2 The ‘if…else’ Statement
14.2.3 Nested ‘if…else’ Statements
14.2.4 The ‘switch’ Statement
14.3 Iteration in Java
14.3.1 The ‘for’ Loop
14.3.2 The ‘while’ Loop
14.3.3 The ‘do…while’ Loop
14.3.4 Picking the Right Loop
14.4 Menu-Driven Programs in Java
14.5 The ‘break’ and ‘continue’ Statements
14.6 Self-test Questions
14.7 Programming Exercises
15 Java Methods
15.1 Introduction
15.2 Declaring and Defining Methods
15.3 Calling a Method
15.4 Method Input and Output
15.5 More Examples of Methods
15.6 Method Overloading
15.7 Built-in Methods of the Math Class
15.8 Self-test Questions
15.9 Programming Exercises
16 Java Arrays
16.1 Introduction
16.2 Creating an Array in Java
16.3 Accessing Array Elements
16.4 The Enhanced ‘for’ Loop
16.5 Passing Arrays as Parameters
16.6 Some Useful Array Methods
16.6.1 Array Maximum
16.6.2 Array Summation
16.7 Variable Arguments
16.8 Returning an Array from a Method
16.9 The Arrays Class
16.10 Multidimensional Arrays
16.10.1 Creating a Two-Dimensional Array
16.10.2 Initializing Two-Dimensional Arrays
16.10.3 Processing Two-Dimensional Arrays
16.10.4 The MonthlyTemperatures Program
16.11 Ragged Arrays
16.12 Self-test Questions
16.13 Programming Exercises
17 Object-Oriented Java: Part 1
17.1 Introduction
17.2 Classes and Objects in Java
17.2.1 The Rectangle Class
17.2.2 The RectangleTester Program
17.3 Strings
17.3.1 The Methods of the String Class
17.3.2 Comparing Strings
17.3.3 Entering Strings Containing Spaces
17.4 Our Own Scanner Class for Keyboard Input
17.5 The BankAccount Class
17.6 Passing Objects as Parameters
17.7 Arrays of Objects
17.8 Implementing the Rectangle Class
17.9 Implementing the BankAccount Class
17.10 The static Keyword
17.11 Initializing Attributes
17.12 The EasyScanner Class
17.13 Self-test Questions
17.14 Programming Exercises
18 Object-Oriented Java: Part 2
18.1 Introduction
18.2 The Employee and PartTimeEmployee Classes
18.3 Implementing Inheritance in Java
18.4 Method Overriding
18.5 Abstract Classes
18.6 Abstract Methods
18.7 The Final Modifier
18.8 The Object Class
18.9 Self-test Questions
18.10 Programming Exercises
19 Java: Interfaces and Lambda Expressions
19.1 Introduction
19.2 An Example
19.3 Interfaces
19.4 Lambda Expressions
19.4.1 The Syntax of Lambda Expressions
19.4.2 Variable Scope
19.4.3 Example Programs
19.4.4 Method References—The Double Colon Operator
19.5 Wrapper Classes and Autoboxing
19.6 Generics
19.7 Other Interfaces Provided with the Java Libraries
19.8 Self-test Questions
19.9 Programming Exercises
20 Java: Exceptions
20.1 Introduction
20.2 Predefined Exception Classes in Java
20.3 Handling Exceptions
20.4 The ‘try-with-resources’ Construct
20.5 Exceptions in Graphical Applications
20.6 Using Exceptions in Your Own Classes
20.7 Creating Your Own Exception Classes
20.8 Self-test Questions
20.9 Programming Exercises
21 The Java Collections Framework
21.1 Introduction
21.2 The List Interface and the ArrayList Class
21.2.1 Creating an ArrayList Collection Object
21.2.2 The Interface Type Versus the Implementation Type
21.2.3 List Methods
21.3 The Enhanced for Loop and Java Collections
21.4 The forEach Loop
21.5 The Map Interface and the HashMap Class
21.5.1 Map Methods
21.5.2 Iterating Through the Elements of a Map
21.6 The Set Interface and the HashSet Class
21.7 Using Your Own Classes with Java’s Collection Classes
21.7.1 The Book Class
21.7.2 An Alternative Implementation
21.8 Sorting a Collection
21.8.1 Sorting Other Objects
21.9 Self-test Questions
21.10 Programming Exercises
22 Java: Working with Files
22.1 Introduction
22.2 File Handling in Java
22.3 Reading and Writing to Text Files
22.4 Reading and Writing to Binary Files
22.5 Reading a Text File Character by Character
22.6 Object Serialization
22.7 Random Access Files
22.8 Self-test Questions
22.9 Programming Exercises
23 Introducing JavaFX
23.1 Introduction
23.2 JavaFX: An Overview
23.3 2D Graphics: The SmileyFace Class
23.4 Event-Handling in JavaFX: The ChangingFace Class
23.5 Some More 2D Shapes
23.6 An Interactive Graphics Class
23.7 Number Formatting
23.8 A Graphical User Interface (GUI) for the Rectangle Class
23.9 Containers and Layouts
23.9.1 More About HBox and VBox
23.9.2 GridPane
23.9.3 StackPane
23.10 Key Events
23.11 More Input Options
23.11.1 Combo Boxes
23.11.2 Check Boxes and Radio Buttons
23.11.3 Drop-Down Menus
23.11.4 Pop-Up Dialogues
23.12 Self-test Questions
23.13 Programming Exercises
24 Java Case Study
24.1 Introduction
24.2 Packages
24.3 Javadoc
24.4 System Overview
24.5 Requirements Analysis and Specification
24.6 Design
24.7 Enumerated Types in UML
24.8 Implementation
24.8.1 Implementing Enumerated Types in Java
24.8.2 The Runway Class
24.8.3 The Plane Class
24.8.4 The Airport Class
24.9 Testing
24.10 Design of the JavaFX Interface
24.11 The TabPane Class
24.12 The AirportFrame Class
24.13 Self-test Questions
24.14 Programming Exercises
Appendix Compiling and Running Java Programs
Outline placeholder
Apache NetBeans
Other Popular IDEs
Index