Question
/** * Identify all errors in this class */ public class Errors { // instance variables - replace the example below with your own private
/** * Identify all errors in this class */ public class Errors { // instance variables - replace the example below with your own private int x;
/** * Constructor for objects of class Errors */ public Errors( ) { int x = 10; }
public Errors( int number ) { number = number; }
public void setX( int number ) { number = this.x; }
public boolean equals( int number ) { if (x = number) { return true; } }
public String toString { String result = ""; this.result += "x = " + this.x; return this.result; }
public static void main( String[ ] args ) { Errors errors1 = new Errors( ); Errors errors2 = new Errors( 22 ); System.out.println( errors1.toString ); System.out.println( errors2.toString ); errors1.setX( 44 ); System.out.println( errors1.toString( ) ); } }
-----------------------------------------------------------------
String Class
/** * For the correctly coded String class, the main * method should print the following in the BlueJ * Terminal Window: * * Name * 02468 * 0369 * */
public class Strings { private String word;
/** * As a general rule, a constructor initializes * all instance variables. Following this rule, * write the code to define the following * constructor. */ public Strings( String w ) { }
/** * Write the code for the following method so * that it returns a String for the word field * in the object with the first character in * uppercase and all subsequence characters * in lower case. * * Allow for the possibility that the word * field might be the null String or have * a String length of 0, i.e. an empty String. * */ public String firstLetterCaps( ) { }
/** * Write the code for the following method so * that it returns a String from the word field * in the object that includes only the even * indexed characters: 0,2,4, etc. */ public String everyOtherLetter( ) {
} /** * Write the code for the following method so * that it returns a String from the word field * in the object that includes ever third * character: 0,3,6,etc. * indexed characters, 0,2,4, etc. */ public String everyThirdLetter( ) {
}
public static void main( String[ ] args ) { Strings strings1 = new Strings( "naME" ); System.out.println( strings1.firstLetterCaps() ); Strings strings2 = new Strings( "0123456789" ); System.out.println( strings2.everyOtherLetter() ); System.out.println( strings2.everyThirdLetter() ); } }
------------------------------------------------
/** * Write a description of class PointXY here. * * @author (your name) * @version (a version number or a date) */ public class PointXY // class declaration { public int x; // field declaration public int y; // field declaration public PointXY( ) // constructor { this.x = 0; // antecedent for pronoun this point1, ..., or point4 this.y = 0; } public PointXY( int x0, int y0 ) // x0 and y0 are parameters { this.x = x0; this.y = y0; } public String toString( ) // method { String result; // local variable result = "(" + this.x + "," + this.y + ")"; return result; // return statement } public static void main( String[ ] args ) { PointXY point1 = new PointXY( ); // PointXY declaraction and instantiation PointXY point2 = new PointXY( 3, 4 ); // 3 and 4 are arguments PointXY point3 = new PointXY( 5, 12 ); PointXY point4 = point3;
point1.x = 22; point1.y = 33; // point1.toString( ) is an example of an object.method call System.out.println( "point1 = " + point1.toString( ) ); System.out.println( "point2 = " + point2.toString( ) ); System.out.println( "point3 = " + point3.toString( ) ); System.out.println( "point4 = " + point4.toString( ) ); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started