Anda di halaman 1dari 12

Nama : Anas Noor Hakim

NIM : 21120120130092
TUGAS 1 PBO LANJUT

Vocabullary
• Mutators : A method that can modify an object.
• Accessors : A method that can access the contents of an object but does
not modifythat object.
• ArrayList : Object that can store multiple object types and can grow
and shrinkdynamically as required.
• Inheritance : The process where one object acquires the properties of
another.
• Isolation Testing : Allows you to check the quality of the code for a
classindependent of the rest of the program code.

Try it/Solve it
1. JavaBank Case Study: Installed
2. Explore & Report observation
What happens when you:
- Display accounts:

Program akan menampilkan pesan bahwa belum ada akun yang dibuat ketika belum
ada yang dibuat.
Nama : Anas Noor Hakim
NIM : 21120120130092
TUGAS 1 PBO LANJUT

Program akan menampilkan “Name”, “Account Number” dan “Balance” ketika sudah
ada akun yang dibuat.

- Create Accounts

Program akan menampilkan pesan bahwa “Name” dan “Account Number” harus diisi
untuk membuat akun.

Program akan menampilkan “Name”, “Account Number” dan “Balance”.

- Delete Accounts
Nama : Anas Noor Hakim
NIM : 21120120130092
TUGAS 1 PBO LANJUT

Program akan menampilkan pesan error bahwa fitur belum didukung pada versi
tersebut.

- Make a Withdrawal Transaction

Opsi ini akan mengambil Account Number, jika saya punya 2 akun dengan nomor yang
sama, program mengambil keduanya dan mengurangi jumlahnya masing-masing.
Namun, masih sedikit kurang bahwa saya bisa mendapatkan nilai minus untuk
“Balance”.

- Make a Deposit Transaction

Program Ini mirip dengan opsi terakhir (Withdrawl) tetapi dalam hal ini nilainya akan
meningkat.menampilkan saldo dari hasil “Balance” ditambah “Deposit”

- Can you display accounts before any are created?

Tidak bisa. Program akan menampilkan pesan bahwa belum ada akun yang dibuat.
Nama : Anas Noor Hakim
NIM : 21120120130092
TUGAS 1 PBO LANJUT

- Can you create an account without entering anything in the fields?

Tidak bisa. Program akan menampilkan pesan error bahwa field “Name” dan “Account
Number” harus diisi.

- Can you make a withdrawal transaction with no amount in the Withdrawal field?
Ya, itu berhasil tetapi tanpa hasil, karena program akan mengurangi nilai “Balance”
dengan nilai 0.

- Can you do a deposit transaction with no amount in the Deposit field?


Bisa. Tetapi jumlah balance tidak akan berubah, karena program akan mendeteksi
deposit berdasarkan jumlah yang dimasukkan pada “Deposit”.

- What other questions do you have about the JavaBank application?


Mengapa pada opsi “Delete”, pesan yang muncul adalah Delete isn’t coded yet.

- What changes would you make to the current application to make it function
better?
Membuat confirmatiom box untuk setiap opsi yang ada.
Sertakan opsi Delete.
Terapkan pengecualian atau metode untuk membuat Nomor Akun secara otomatis dan
nomor akun tidak boleh sama.
Nama : Anas Noor Hakim
NIM : 21120120130092
TUGAS 1 PBO LANJUT

- What additions would you make to the current application to increase its
functionality?
Membuat jenis akun yang berbeda.

3. Bikeproject
a. Give an example of a primitive data type that is used to store fields within a class.
Kita bisa menggunakan int, long, short, double, float, Boolean dan char. Setidaknya
pada program ini saya hanya bisa melihat tipe data int yang diimplementasikan.

b. Give an example of where String concatenation takes place.


public void printDescription()
{
super.printDescription();
System.out.println("This mountain bike is a " +
this.type + " bike and has a " + this.suspension + " suspension and
a frame size of " + this.frameSize + "inches.");

}//end method printDescription

c. What are the names of the objects created in this program?


Bike, MountainBike and RoadBike

d. How many constructors does each class have?


Bike: 2
MountainBike: 2
RoadBike: 3

e. Inheritance is part of this program. Identify the Super and subclasses from this
program.
Super: Bike
SubClasses: MountainBike and RoadBike
Nama : Anas Noor Hakim
NIM : 21120120130092
TUGAS 1 PBO LANJUT

f. Mountain bikes and road bikes can be constructer either by using the default
values (standard bike) or customized to the client’s needs. Using the following
table identify sample values assigned to one of each type of standard bike

Already for Mountain Bike we use the next constructor:

public MountainBike()
{
this("Bull Horn", "Hardtail", "Maxxis", "dropper", 27,
"RockShox XC32", "Pro", 19);
}//end constructor

And for Road Bike:


public RoadBike()
{
this("drop", "racing", "tread less", "razor", 19, 20,
22);
}//end constructor
Nama : Anas Noor Hakim
NIM : 21120120130092
TUGAS 1 PBO LANJUT

4. Calculator Program

- Determine what Calculator does and how it works – investigate.


Saya sudah menggunakan aplikasi dan sepertinya berfungsi kurang, seperti aplikasi
hanya dapat menjumlahkan 2 angka kemudian rusak total. Itu melempar pengecualian
jika Anda menekan = ketika Anda tidak memasukkan data

- Add multiplication and subtraction buttons to the application.


Nama : Anas Noor Hakim
NIM : 21120120130092
TUGAS 1 PBO LANJUT

- Test to make sure all functionality works as you expect.

Saya mengetes dengan 5 x 4 dan hasilnya telah sesuai yaitu 20.0

Saya mengetes dengan 10 – 2 dan hasilnya telah sesuai yaitu 8.0

package calculator;
import javax.swing.*;
import java.awt.Color;
import java.awt.event.*;

public class CalcPanel extends JPanel implements ActionListener {


String num1="";
String num2="";
String operator="";
Nama : Anas Noor Hakim
NIM : 21120120130092
TUGAS 1 PBO LANJUT

boolean usingFirst=true;
double total=0;

JTextField display;
JButton b1;
JButton b2;
JButton b3;
JButton b4;
JButton b5;
JButton b6;
JButton b7;
JButton b8;
JButton b9;
JButton b0;
JButton bdec;
JButton bclear;
JButton bequals;
JButton bplus;

//ADDED BUTTONS
JButton bmultiplication;
JButton bsubstraction;

public CalcPanel()
{
this.setBackground(Color.white);
setLayout(null);
display=new JTextField();
b1=new JButton("1");
b2=new JButton("2");
b3=new JButton("3");
b4=new JButton("4");
b5=new JButton("5");
b6=new JButton("6");
b7=new JButton("7");
b8=new JButton("8");
b9=new JButton("9");
b0=new JButton("0");
bdec=new JButton(".");
bclear=new JButton("C");
bequals = new JButton( "=");
bplus=new JButton("+");

//ADDED BUTTONS
bmultiplication = new JButton("x");
bsubstraction = new JButton("-");
//END ADDED BUTTONS

display.setBounds(0,0,205,50);
b1.setBounds(0,200,50,50);
b2.setBounds(50,200,50,50);
b3.setBounds(100,200,50,50);
Nama : Anas Noor Hakim
NIM : 21120120130092
TUGAS 1 PBO LANJUT

bplus.setBounds(154,200,50,50);
b4.setBounds(0,150,50,50);
b5.setBounds(50,150,50,50);
b6.setBounds(100,150,50,50);
b7.setBounds(0,100,50,50);
b8.setBounds(50,100,50,50);
b9.setBounds(100,100,50,50);
b0.setBounds(0,250,50,50);
bdec.setBounds(50,250,50,50);
bclear.setBounds(100,250,50,50);
bequals.setBounds(154,250,50,50);
bmultiplication.setBounds(154, 150, 50, 50);
bsubstraction.setBounds(154, 100, 50, 50);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(b0);
add(bdec);
add(display);
add(bclear);
add(bequals);
add(bplus);
add(bmultiplication);
add(bsubstraction);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b0.addActionListener(this);
bequals.addActionListener(this);
bplus.addActionListener(this);
bclear.addActionListener(this);
bdec.addActionListener(this);
bmultiplication.addActionListener(this);
bsubstraction.addActionListener(this);
}

public void actionPerformed(ActionEvent e){


String s=e.getActionCommand();
if(s.equals("1")||s.equals("2")||s.equals("3")||
Nama : Anas Noor Hakim
NIM : 21120120130092
TUGAS 1 PBO LANJUT

s.equals("4")||
s.equals("5")||s.equals("6")||s.equals("7")||
s.equals("8")||
s.equals("9")||s.equals("0")||s.equals("."))
{
if(usingFirst){
num1=num1+s;
display.setText(num1);
}
else
{
num2=num2+s;
display.setText(num2);

}
}

if(s.equals("+")||s.equals("-")||s.equals("x"))
{
usingFirst=false;
if (s.equals("+"))
operator="+";
else if (s.equals("-"))
operator="-";
else if (s.equals("x"))
operator="x";
}

if(s.equals("="))
{
switch(operator){
case "+":

total=Double.parseDouble(num1)+Double.parseDouble(num2);
display.setText( ""+total );
break;
case "x":

total=Double.parseDouble(num1)*Double.parseDouble(num2);
display.setText( ""+total );
break;
case "-":
total=Double.parseDouble(num1) +
(Double.parseDouble(num2)*(-1));
display.setText( ""+total );
break;
}

System.out.println(num2);
usingFirst=true;
num1="";
num2="";
Nama : Anas Noor Hakim
NIM : 21120120130092
TUGAS 1 PBO LANJUT

operator="";
}

if(s.equals("C"))
{
display.setText( "" );
usingFirst=true;
num1="";
num2="";
total=0;
}
}
}

Anda mungkin juga menyukai