TUGAS ARRAY DAN INHERITANCE KELOMPOK 13 SI4002


INHERITANCE

Define two derived classes of the abstract class ShapeBase in Listing 8.19. Your two classes will
Your two classes will be called RightArrow and LeftArrow. These classes will be like the Classes
Rectangle and Triangle, but they will draw arrows that point right and left, respectively

class Leftarrow {
public static void main(String[] args) {
ThisArrow row = new ThisArrow();
row.printLeftArrow(‘*’, 3);
row.printLeftArrow(‘#’, 7);
}
}

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package rightarrow;

/**
*
* @author Ichwan pc
*/
public class Rightarrow {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ThisArrow row = new ThisArrow();
row.printRightArrow(‘*’, 3);
row.printRightArrow(‘#’, 7);
}

}

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package rightarrow;

import java.util.Arrays;

/**
*
* @author Ichwan pc
*/
public class ThisArrow {
private static String repeat(char ch, int count) {
char[] buf = new char[count];
Arrays.fill(buf, ch);
return new String(buf);
}
public static void printRightArrow(char ch, int n) {
for (int i = 1; i < n; i++)
System.out.println(repeat(‘ ‘, n – 1) + repeat(ch, i));
System.out.println(repeat(ch, n * 2 – 1));
for (int i = n-1; i >= 1;i–)
System.out.println(repeat(‘ ‘, n – 1) + repeat(ch, i));
}
public static void printLeftArrow(char ch, int n) {
for (int i = 1; i < n; i++)
System.out.println(repeat(‘ ‘, n – i) + repeat(ch, i));
System.out.println(repeat(ch, n * 2 – 1));
for (int i = n -1; i >=1; i–)
System.out.println(repeat(‘ ‘, n – i) + repeat(ch, i));
}
}

Outputnya:

​untuk Run (Shift + F6) di setiap class LeftArrow maupun di RightArrow


Disini kami memasukan simbol Pagar (#) dan angka 7 di dalam method. Nah maka saat di run akan muncul seperti yang diatas, karena simbol yang kami pilih berupaPagar (#) , dan angka 7 menentukan panjang Pagar dari tengah ujung kiri ke ujung kanan, berupa 7 pagar. Dan sisa nya dari atas kebawah hanya mengikuti bagian Pagar ujung kanan saja untuk membuat segitiga sampai puncaknya satu, baik kebawah maupun keatas

Anggota Kelompok :

Ichwan habibie 1202162252
Fernando Redondo 1202164211
Ghalib Mahendra 1202164187
Syahril J Gugere 1202160227


Leave a Reply