0% found this document useful (0 votes)
37 views

Tugas Pemrograman Berorientasi Objek: Oleh I Kadek Satriawan 1204505004

This document discusses an object-oriented programming assignment involving arrays in Java. It includes the source code for a class called ArrayFull that generates a 2D array of random integers, performs various operations on the array such as rotation, flipping, sorting, and prints the results. The operations include rotating the array 90 degrees, flipping it vertically and horizontally, sorting the values, and rotating it 180 degrees counter-clockwise.

Uploaded by

Satriawan Achaa
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Tugas Pemrograman Berorientasi Objek: Oleh I Kadek Satriawan 1204505004

This document discusses an object-oriented programming assignment involving arrays in Java. It includes the source code for a class called ArrayFull that generates a 2D array of random integers, performs various operations on the array such as rotation, flipping, sorting, and prints the results. The operations include rotating the array 90 degrees, flipping it vertically and horizontally, sorting the values, and rotating it 180 degrees counter-clockwise.

Uploaded by

Satriawan Achaa
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

TUGAS PEMROGRAMAN BERORIENTASI OBJEK

Oleh I KADEK SATRIAWAN 1204505004

PROGRAM STUDI TEKNOLOGI INFORMASI FAKULTAS TEKNIK UNIVERSITAS UDAYANA TAHUN 2013

Source Code :
package array; import java.util.*; /** * * @author satria */ public class ArrayFull { public static void main(String[] args){ Scanner inColumn = new Scanner(System.in); Scanner inRow = new Scanner(System.in); System.out.print(" Input Column : "); int baris = inColumn.nextInt(); System.out.print(" Input Rows : "); int kolom = inColumn.nextInt(); System.out.println("Matrix printArray(baris,kolom); } static int[][] rotate(int[][] arr) { int width = arr[0].length; int depth = arr.length; int[][] re = new int[width][depth]; for (int i = 0; i < depth; i++) { for (int j = 0; j < width; j++) { re[j][depth - i - 1] = arr[i][j]; } } return re; } static void printArray(int baris, int kolom){ int[][] array = new int[baris][kolom]; for (int i=0; i < array.length; i++){ for(int j=0; j < array[i].length; j++){ array[i][j] = (int) (Math.random()*255); ["+baris+"]["+kolom+"] : "); System.out.println("-------------------------------");

} } // print for (int[] row : array) { System.out.println(Arrays.toString(row)); } // rotate 90 int[][] matriks =rotate(array); // System.out.println("After Rotate 90 degree : "); for (int[] cell : matriks) { System.out.println(Arrays.toString(cell)); } // Rotate 180 int[][] // System.out.println("After Rotate 180 degree : "); for (int[] cell3 : matriksHorz) { System.out.println(Arrays.toString(cell3)); } // Flip Vertical int[][] matriksVertical = flipVertical(array);; // System.out.println("After Flip Vertical : "); for (int[] cell2 : matriksVertical) { System.out.println(Arrays.toString(cell2)); } // Flip Vertical int[][] matriksHz = flipHorz(array);; // System.out.println("After Flip Horizontal : "); for (int[] cell4 : matriksHz) { System.out.println(Arrays.toString(cell4)); } // Sort matriksHorz = rotateCCW(array);;

int[][] matriksSort = sort(array);; // System.out.println("After Sort : "); for (int[] cell5 : matriksSort) { System.out.println(Arrays.toString(cell5)); }

} // Flip Array Vertical static int[][] flipVertical(int[][] theArray) { for(int i = 0; i < (theArray.length / 2); i++) { int[] temp = theArray[i]; theArray[i] = theArray[theArray.length - i - 1]; theArray[theArray.length - i - 1] = temp; } return theArray; } // Flip Array Horizontal static int[][] flipHorz(int[][] theArray) { for(int i=0; i< theArray.length; i++){ int indeks = 0; for(int j = theArray[0].length - 1; j > -1; j--){ theArray[i][indeks] = theArray[i][j]; indeks++; } } return theArray; } // Rotate 180 public static int[][] rotateCCW(int[][] matriks) { int o = matriks.length; int p = matriks[0].length; int[][] out = new int[o][p]; for (int i = 0; i < o; i++) {

for (int j = 0; j < p; j++) { out[i][p - j - 1] = matriks[i][j]; } } return out; } public static int[][] sort(int list[][]) { boolean sort; do { sort = true; int[] temp; for (int i = 0; i < list.length - 1; i++) { if (list[i][1] > list[i + 1][1]) { temp = list[i]; list[i] = list[i + 1]; list[i + 1] = temp; sort = false; } } } while (!sort); return list; } }

Screenshoot setelah decompile dan di jalankan pada IDE Netbeans sebagai berikut :

You might also like