程序代写 CS61B: Lecture #11 1 – cscodehelp代写

Recreation
An integer is divided by 9 when a certain one of its digits is deleted, and the resulting number is again divisible by 9.
a. Prove that actually dividing the resulting number by 9 results in deleting another digit.
b. Find all integers satisfying the conditions of this problem.

Copyright By cscodehelp代写 加微信 cscodehelp

Last modified: Thu Feb 13 20:48:25 2020 CS61B: Lecture #11 1

Project Ethics
Basic Rules:
1. By You Alone: All major submitted non-skeleton code should be writ- ten by you alone.
2. Do Not Possess or Share Code: Before a project deadline, you should never be in possession of solution code that you did not write, nor distribute your own code to others in the class.
3. Cite Your Sources: When you receive significant assistance on a project from someone else (other than the staff), cite that assis- tance somewhere in your source code.
Last modified: Thu Feb 13 20:48:25 2020 CS61B: Lecture #11 2

Ethical Collaboration
Unproblematic
• Discussion of approaches for solving a problem.
• Giving away or receiving significant ideas towards a problem solution,
• Discussion of specific syntax issues and bugs in your code.
• Using small snippets of code that you find online for solving tiny problems (e.g. googling “uppercase string java” may lead you to some sample code that you copy and paste. Cite these.
Requiring Great Caution:
• Looking at someone else’s project code to assist with debugging.
• Looking at someone else’s project code to understand a particular idea or part of a project. Generally unwise though, due to the danger of plagiarism.
Last modified: Thu Feb 13 20:48:25 2020 CS61B: Lecture #11 3

Unethical Collaborations
• Possessing another student’s project code in any form before a final deadline, or distributing your own.
• Possessing project solution code that you did not write yourself be- fore a final deadline (e.g., from github, or from staff solution code found somewhere). Likewise, distributing such code.
Last modified: Thu Feb 13 20:48:25 2020 CS61B: Lecture #11 4

CS61B Lecture #11: Examples: Comparable & Reader
Last modified: Thu Feb 13 20:48:25 2020 CS61B: Lecture #11 5

Comparable
• Java library provides an interface to describe Objects that have a natural order on them, such as String, Integer, BigInteger and BigDecimal:
public interface Comparable { // For now, the Java 1.4 version /** Returns value <0, == 0, or > 0 depending on whether THIS is
* <, ==, or > OBJ. Exception if OBJ not of compatible type. */
int compareTo(Object obj); }
• Might use in a general-purpose max function:
/** The largest value in array A, or null if A empty. */
public static Comparable max(Comparable[] A) { if (A.length == 0) return null;
Comparable result; result = A[0];
for (int i = 1; i < A.length; i += 1) if (result.compareTo(A[i]) < 0) result = A[i]; return result; • Now max(S) will return maximum value in S if S is an array of Strings, or any other kind of Object that implements Comparable. Last modified: Thu Feb 13 20:48:25 2020 CS61B: Lecture #11 6 Examples: Implementing Comparable /** A class representing a sequence of ints. */ class IntSequence implements Comparable { private int[] myValues; private int myCount; public int get(int k) { return myValues[k]; } public int compareTo(Object obj) { IntSequence x = (IntSequence) obj; // Blows up if obj not an IntSequence for(inti=0;i x.myValues[i]) { return 1;
return myCount – x.myCount; // <0 iff myCount < x.myCount } Last modified: Thu Feb 13 20:48:25 2020 CS61B: Lecture #11 7 Implementing Comparable II • Also possible to add an interface retroactively. • If IntSequence did not implement Comparable, but did implement compareTo (without @Override), we could write class ComparableIntSequence extends IntSequence implements Comparable { } • Java would then “match up” the compareTo in IntSequence with that in Comparable. Last modified: Thu Feb 13 20:48:25 2020 CS61B: Lecture #11 8 Java Generics (I) • We’ve shown you the old Java 1.4 Comparable. The current version uses a newer feature: Java generic types: public interface Comparable { int compareTo(T x);
• Here, T is like a formal parameter in a method, except that its
“value” is a type.
• Revised IntSequence (no casting needed):
class IntSequence implements Comparable { …
public int compareTo(IntSequence x) {
for(inti=0;iCS代考 加微信: cscodehelp QQ: 2235208643 Email: kyit630461@163.com

Leave a Reply

Your email address will not be published. Required fields are marked *