Note: Unless otherwise instructed, use BlueJ to complete the assignments. Save all work under your cs176
or cs501b
folder in your school UNIX account.
Deadline:
Save all work under the folder cs176/Assignment1/
(or cs501b/Assignment1/
) in your UNIX home folder.
Write and test a method that sums all the integers in a matrix of integers. Use 1_2_4_5_6_7_8_9_10_11_12_13_14_15_16_17 to test the method.
Submit the SumMatrix.java file only.
Write and test a method that sums all the integers in the major diagonal in an n x n matrix of integers. Use 1_2_4_5_6_7_8_9_10_11_12_13_14_15_16_17 to test the method.
Submit the SumMatrixDiag.java file only.
Write a program that randomly fills in 0s and 1s into a TicTacToe board, prints the board, and finds the rows, columns, or diagonals with all 0s or 1s. Use a two-dimensional array to represent a TicTacToe board. Here is a sample run of the program:
001 001 111 All 1's on row 2 All 1's on column 2
Submit the T3Board.java file only.
Deadline:
Save all work under the folder cs176/Assignment2/
(or cs501b/Assignment2/
) in your UNIX home folder.
Note: Indent your code properly or use the bluej auto-layout feature.
Save and submit as BubbleSortString.java.
See some online notes on 1D array bubble sorts.
Complete the following method that sorts an array of Strings in ascending lexicographical order.
public static void bubbleSortString(String[] s) { }
Include a main method that creates an unsorted one-dimensional array of Strings and uses the bubbleSortString method to sort the string array. The main method should then output the sorted array of Strings. Use this array of Strings to test your method.
Complete the following method that outputs the row and column location of the largest element in a two-dimensional array.
public static void locateLargest(double[][] a) { }
Include a main method that creates a two-dimensional array of doubles and uses the locateLargest method to display the location of the largest element in the array. Here is a sample run:
In the following array: 23.5 35 2 10 4.5 3 45 3.5 35 44 5.5 9.6 The largest element is 45 at row 2, column 3.
Deadline:
Save all work under the folder cs176/Assignment3/
(or cs501b/Assignment3/
) in your UNIX home folder.
Note: Indent your code properly or use the bluej auto-layout feature.
private String _shown; // What a square is showing now private boolean _mined; // Square is mined or not private boolean _flagged; // Square is flagged or not private boolean _questioned; // Square is question marked or not private int _minecount; // Square's surrounding mine count private boolean _opened; // Player has opened this square or not
Create all needed get and set methods for these variables.
The possible values for the _shown String variable would be:
Think about how the MineSquare class variables might be related. For example, if a player puts a flag on a square, what would that square be showing? And, if a player opens a square, what would that square be showing?
You do not need to write a program to test the MineSquare class at this time.
Deadline:
Save all work under the folder cs176/Assignment4/
(or cs501b/Assignment4/
) in your UNIX home folder.
Note: Indent your code properly or use the bluej auto-layout feature. Also, comment your code to explain what you are doing.
// // Code that goes in TestFraction2.java: // Fraction2 f1 = new Fraction2( 5, 8 ); Fraction2 f2 = new Fraction2( 1, 9 ); Fraction2 f3 = new Fraction2(); // This time, addFraction is an instance method of the Fraction2 // class, so we use the object f3's addFraction() method, i.e., // f3.addFraction(). f3.addFraction( f1, f2 ); // f3 holds the result of 5/8 + 1/9 System.out.println( f1.printFraction() + " + " + f2.printFraction() + " = " + f3.printFraction() );
In at least 200 words, summarize in your own words the code commenting guidelines at http://tinyurl.com/ms5ev77.
Save your answers in a plain text file called Good_Comments.txt. Recommended plain text editors: jedit, notepad++.
Deadline:
Save all work under the folder cs176/Assignment5/
(or cs501b/Assignment5/
) in your UNIX home folder.
Note: Indent your code properly or use the bluej auto-layout feature. Also, comment your code to explain what you are doing.
In at least 200 words, summarize in your own words the class design guidelines given in the document that was emailed or handed out to you as part of this assignment. Be sure to include descriptions of what cohesion and coupling are.
Save your answers in a plain text file called Class_Design.txt. Do not submit a .docx file. Recommended plain text editors: jedit, notepad++. If you are typing this in UNIX, use the gedit text editor.
24 35 2 10 5 3 45 4 35 44 6 9 8 15 25 11
Deadline:
Save all work under the folder cs176/Assignment6/
(or cs501b/Assignment6/
) in your UNIX home folder.
Note: Indent your code properly or use the bluej auto-layout feature. Also, comment your code to explain what you are doing.
The BlueJ project you create should contain Person.java, Student.java, StudentYear.java, Employee.java, Faculty.java, Staff.java, and TestPersons.java.
Design a class named Person and its two subclasses named Student and Employee.
// put this in StudentYear.java public enum StudentYear { FRESHMAN, SOPHMORE, JUNIOR, SENIOR }
Keep the class files simple and short by using inheritance. In all the subclasses (every class besides Person), the only method you define should be the toString method.
Use the following TestPersons class to test the above classes:
// TestPersons.java: // creates Person, Student, Employee, Faculty, and Staff objects public class TestPersons { public static void main(String[] args) { Person pete = new Person(); pete.setName("Pete"); System.out.println(pete + "\n"); Student stan = new Student(); stan.setName("Stan"); System.out.println(stan + "\n"); Employee ernie = new Employee(); ernie.setName("Ernie"); System.out.println(ernie + "\n"); Faculty coddington = new Faculty(); coddington.setName("Coddington"); System.out.println(coddington + "\n"); Staff starr = new Staff(); starr.setName("Starr"); System.out.println(starr); } }
The BlueJ project you create should contain Fraction.java and FractionCalc.java.
Complete the FractionCalc GUI that we have been working on in class. Include a fourth button for the division operation. Yes, you will need to add a working divideFraction method to the Fraction class.
Write your answers in Polymorphism.txt and save it.
Read http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html on the instanceof operator. Then answer the following questions about the GeometricObject1 and Triangle classes:
Given the following declarations:
Triangle triangle = new Triangle(); GeometricObject1 object1 = new GeometricObject1();
1) Are the following boolean expressions true or false?
(triangle instanceof GeometricObject1) (object1 instanceof GeometricObject1) (triangle instanceof Triangle) (object1 instanceof Triangle)
2) Can the following statement be compiled?
GeometricObject1 object = triangle;
3) Can the following statements be compiled?
GeometricObject1 object = new GeometricObject1(); Triangle triangle = (Triangle)object;
4) From (3) above, what is the meaning of the following statement?
Triangle triangle = (Triangle)object;