Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
UMKD SDP2 2016-2017.docx
Скачиваний:
25
Добавлен:
14.10.2016
Размер:
126.72 Кб
Скачать

Instructions

  1. Use the word processor on the computer to fill in this assessment.

  2. Start by inserting your name in the space above.

  3. Before you begin answering these questions, save this file using the require file name format: “<YourAndrewID> Quiz05.doc” where <YourAndrewID> is your AndrewID and there is a blank between it at the Quiz05. When you are finished with the quiz, save the document again and then upload it to the LMS.

Assessment questions

  1. What would the following code display?

int sum = 0;

for (int i=0; i < 4; i++){

for (int j=i; j < 4; j++){

sum += j;

System.out.print(sum + " ");

}

System.out.println();

}

Place your output here:

  1. Write the java code required to solve the following problem. Given the expression below, which properly determines if a specified year is a leap year, write a Java program that reads in a line from the console keyboard. If the line is empty, the program stops. If the line is not empty, the line will contain one valid. (You do not need to check for valid input!) The integer is a year. Print the year and whether it is a leap year or not.

(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)

Place your output here:

Instructions

  1. Use the word processor on the computer to fill in this assessment.

  2. Start by inserting your name in the space above.

  3. Before you begin answering these questions, save this file using the require file name format: “<YourAndrewID> Quiz06.doc” where <YourAndrewID> is your AndrewID and there is a blank between it at the Quiz06. When you are finished with the quiz, save the document again and then upload it to the LMS.

Assessment questions

  1. What would the following code display?

String stringA = "How worldly is that?";

String probe = "howdy";

int hitCount = 0;

char c;

for (int i=0;i<probe.length();i++) {

c = probe.charAt(i);

for (int j=0;j<stringA.length();j++) {

if (stringA.charAt(j) == c)

hitCount++;

}

}

System.out.println(hitCount+" hits");

Place your output here:

  1. Write the java code required to solve the following problem. Using a class's constructor to initialize values, create a Java Class which offers the following two public methods:

Date getCreationDate();

String getCreatorName();

Place your output here:

7. Methodological guidelines for sis

Project 01: Integer Calculator

OVERVIEW

In Project 01 the students are given the source code for an integer calculator program that they need to modify to make it function correctly. These changes are fairly easy to make:

  • They only need to add new code in four places: where the actual addition, multiplication, division and subtraction of the entered numbers occurs.

  • These four locations are marked with comments that are easy for the students to find.

  • The students will need to modify the comments in the source files to indicate that they are the owner of the code while still recognizing the original author. This task simply requires the students to update the block comments already in the program. A reading has been provided that describes how to do this (since block comments are not covered in the book).

  • The students will need to "debug" problems in their code. For this course please guide the students to insert print statements at key locations in their code, where the print statements print key information needed to solve the problem to the console. The course already covers a lot in a short amount of time, so it is recommended that debugging using breakpoints, stepping over/into methods, etc. not be introduced, except possibly as scaffolding if a student is moving much faster than the class as a whole.

  • The students will need to test their updates and make sure that their updates are working correctly. Ask the students to describe how they would know if their updates are working correctly. Good suggestions include:

  • Testing each function (addition, multiplication, division and subtraction) with known good information (that is, only entering integers).

  • Testing known invalid information (for example, entering letters and real numbers)

  • Testing boundary conditions (using integer values that are bigger that what can fit in the unit being used to store the value in the program, multiplying by 0, etc.).

  • In the requirements document the students are asked "what are other error messages that can be produced by this program?"

  • Probably the easiest, and quickest, way to answer this would be to search for all of the message strings in the program.

The most difficult part of this first project will be the students initially feeling that they are not prepared to look at Java source code. Once they overcome this fear and get started they should be able to finish this project without much problem.

Scaffolding

Advanced students can work on:

  • Reading the integer calculator source code that they are given and trying to write a flowchart or pseudo-code for it.

  • Learning how to debug a program by walking through the code and looking at key data elements using a debugger.

Project 02: Floating-point Calculator

OVERVIEW

In Project 02 the students need to modify their Project 01 Integer Calculator so that it works with floating-point values.

These modifications are very similar to the modifications made in Project 01 and, as with Project 01, these changes are fairly easy to make:

  • They only need to add new code in four places: where the actual addition, multiplication, division and subtraction of the entered numbers occurs.

These four locations are the same ones that they changed in Project 01, so they should be easy for the students to find.

Watch for the students not noticing the requirement to change the word “Result” to “Sum”, “Difference”, “Product”, or “Quotient” on the output screen depending upon which operator button has been pressed. If a student does miss this requirement consider it a "teachable moment" and ask the student what would happen if they make that type of mistake in a real work environment.

  • As with Project 01 the students will need to modify the comments in the source files to indicate that they are the owner of the code while still recognizing the original author. This task is the same as with Project 01.

  • Continue to have the students "debug" problems in their code by inserting print statements at key locations in their code.

  • As with Project 01 the students will need to test their updates and make sure that their updates are working correctly. Have the students reflect on their Project 01 testing and identify what they can improve in this area for Project 02. Then check to see if they actually implemented those improvements.

The most difficult part of this second project will be the students initially feeling that they are not prepared to look at Java source code. Once they overcome this fear and get started they should be able to finish this project without much problem.

Encourage the students to collaborate with each other, but to never give someone their answer. If a student is really feeling lost, and working with other students is not working, encourage them to come see you during office hours.

Scaffolding

Advanced students can work on:

  • Reading the floating-point calculator source code that they are given and trying to write a flowchart or pseudo-code for it.

Learning how to debug a program by walking through the code and looking at key data elements using a debugger.

Project 03: Calculator with Error terms

OVERVIEW

In Project 03 the students need to modify their Project 02 floating-point calculator so that it supports error terms. This means that values entered into the calculator can have associated error terms, and the error terms will undergo the same operation as the entered operands.

These modifications are very similar to the modifications made in the previous projects, however it should be apparent that while the work is becoming more and more difficult with each project, students should find these changes are fairly easy to make:

  • Enhancing the user interface by adding two new text input boxes, adding in the “” character (\u00B1 in Unicode), moving the error messages, and widening the result text output window. Note that students are enhancing an existing user interface, and not creating a complete GUI. They should be able to figure out how to add or modify these widgets based on the existing code.

  • Computing the proper error term to be displayed for the result based on information they will find in the “Units and Precision” supplementary reading document, and based on the work they do in the class exercises.

  • Modifying the output in the result box to show both the result of the specified computation as well as the error term for this result. This gives the students the opportunity to use what they have learned about conditional statements and program flow.

  • Continue to have the students "debug" problems in their code by inserting print statements at key locations in their code.

  • Modifying the source file comments in their program so it is clear that the program is theirs, while still recognizing the work of the original author. This is the same as what the students did in their previous projects.

Testing the program and documenting the results. This is the same as what the students did in their previous projects.

Encourage the students to collaborate with each other, especially if they do not understand the assignment, or how to complete it, but to never give someone their answer. If a student is really feeling lost, and working with other students is not working, encourage them to come see you during office hours.

Scaffolding

Advanced students can work on:

  • Reading their calculator source code that they are given and trying to write a flowchart or pseudo-code for it.

  • Stepping through the code using the debugger, setting breakpoints and learning other key debugger features.

Listing the test cases that they believe would represent a complete and thorough validation of their inexact calculator, discussing this list with some of the classmates and identifying whether their classmates thought the list was complete, or not, and why.

Project 04: Hangman

OVERVIEW

In Project 04, the students need to modify an existing Hangman program that they are given to make the game fully functional. However, instead of being told exactly what to change in the program, the students have to figure out what to change based on their knowledge of the game (from playing the game), and from the flowcharts and pseudocode that they are given that describe the game.

The process of making modifications to the source code will be very similar to the process used in the previous projects (figure out where to make the change, make the change and verify that the change is working correctly), however it should be apparent that while the work is becoming more and more difficult with each project, students should still find these changes are fairly easy to make:

  • Comparing the flowchart against the source code they have been given to determine what they will need to change. This is the approach we recommend that the students take to identify all of the changes that they need to make, thereby being able to better plan their project work.

If the student executes the run.bat file in the shell program that they are given, the program executes, but you can't play the game. Another approach that students could take would be to simply keep fixing problems that they find until the program works correctly. While this will eventually get to the point where the program is working, it is much less predictable in terms of time and effort that the approach mentioned above, resulting in the student's inability to plan their work.

  • Continue to have the students "debug" problems in their code by inserting print statements at key locations in their code.

  • Modifying the source file comments in their program so it is clear that the program is theirs, while still recognizing the work of the original author.

This is the same as what the students did in their previous projects.

  • Testing the program and documenting the results.

This is the same as what the students did in their previous projects.

Encourage the students to collaborate with each other, especially if they do not understand the assignment, or how to complete it, but to never give someone their answer. If a student is really feeling lost, and working with other students is not working, encourage them to come see you during office hours.

Scaffolding

Advanced students can work on:

  • Stepping through the code using the debugger, setting breakpoints and learning other key debugger features.

Listing the test cases that they believe would represent a complete and thorough validation of their Hangman program, discussing this list with some of the classmates and identifying whether their classmates thought the list was complete, or not, and why.

Project 05: Basic e-reader

OVERVIEW

In Project 05 students need to modify the eReader to update two different note counts at appropriate times and add a note when requested. The real challenges for students in this project are:

  • understanding the concept of testing the eReader by starting a second instance of Eclipse which has the eReader plugin installed

  • understanding the relationship of the eReader and the eReader delegate

  • understanding concepts explored in exercises (searching, sorting, array resizing, and counting notes) and applying these concepts in a new context

The scaffolding and architecture of the eReader isolates all the student code to the delegate. As an instructor you will recognize that the EReaderDelegate is a base class for the different delegate classes that the students will work in. The point is not to introduce the large concept of subclasses and inheritance to students. However, they must understand for a given exercise or project, they must edit one line of code in the base class EReaderDelegate to create an instance of the class they will be editing, in this case EReaderDelegateProj5.

The actual code changes in the delegate methods are somewhat simple. But understanding when the calls to the delegate methods occur and what user actions initiate them is critical for the students to appreciate.

Scaffolding

Advanced students can work on:

  • Encapsulating the function of counting the number of notes for a given page into a separate method. Counting notes for a page is necessary in order to tell the eReader to update the count in the UI. This is needed in methods pageDisplayed and addNote. It will also be useful in Project 06 when students implement deleting a note.

Project 06: ANNOTATED e-reader

OVERVIEW

In Project 05 students added some basic features to the eReader. In Project 06 the students are asked to implement the more complex features of deleting a note and sorting notes. As before, students will focus all of their efforts in a single class, however, the code for each method will now be more complex.

At this point students should be comfortable with the architecture of the eReader and how to execute it, thus for this project they can focus on coding the specific features. The real challenges will come from deleting a note, so they must apply searching and array resizing. And then, sorting an array of objects by a given key, which will be more difficult than previous sorting exercises. Students will not be able to simply copy and paste their solutions from their exercises, but must apply the coding techniques to a new context. This is an essential skill for all programmers, understanding the essence of a concept and applying it in a new context.

Scaffolding

Advanced students can work on:

  • Writing four different sort methods (or perhaps four different sections of one method) to implement sorting. In fact, using four different sections of one method will likely be their first instinct, one for each key. However, a solution does exist where a single method, or section of code, can do all four types of sorts. The key only affects the comparison of note objects. All other details of the sort code are the same. The comparison can be isolated to one section of code, or even encapsulated in a separate method. The solution for this project implements all sorting in a single section of the addNote method.

  • Carrying the sorting process one step further. To implement the optional advanced sort, students are asked to do sorting by two keys: the page number, and the y position of a note’s document selection. For example, if two notes have a single word selection on the same line of text, their page numbers will be the same and their y position of their selections will be the same. A third key to test is the x position of the selection, such that notes with a smaller x coordinate come before notes with a larger x coordinate. The solution for this project implements this concept.

Project 07: Enhanced calculator

OVERVIEW

In Project 07, students will modify their floating-point calculator so that it supports units of measure along with the error term and extended precision floating-point numbers implemented in Project 03.

Key areas of student learning for Project 07 include:

  • Adding drop-down boxes to the user interface in order to correctly accept the floating-point number, error term and unit of measure for both operands.

  • Converting some units of measure, as appropriate. For example, when multiplying mm * cm, instead of getting an error saying the units are not the same, the student will convert the second operand to match the first operand and then complete the operation.

  • Using tables and table lookup techniques to implement their solution.

  • Ensuring that all floating-point and error term functions continue to work correctly.

  • Testing their updates to make sure that their program is working correctly.

The provided solutions to Project 03 and Exercises 40 - 42 perform many of the actions required to accept user input, work with units, and produce the actual output of the measured value, including the error term. Students can use and enhance that code to support conversion and display of units of measure and display the result in the format “result units +/- error units”.

Enhancement of the floating-point calculator with error terms must not damage the program in terms of recognizing or processing errors. In fact, students must carefully add their new code so that unrecognized units and invalid combination of units also are reported.

By now, students will have considerable practice using Java source code, so they should not have problems getting started with, or finishing, this project.

Encourage students to collaborate with each other, but to never give someone their answer. If a student is really feeling lost, and working with other students is not working, encourage them to come see you during office hours.

Scaffolding

Advanced students can work on:

  • Reading the floating-point calculator source code that they are given and trying to write a flowchart or pseudocode for it.

  • Building the tables to support more units.

Learning how to debug a program by walking through the code and looking at key data elements using a debugger.

Соседние файлы в предмете Программирование на Java