Tugas Personal Ke-2 (Minggu 7 / Sesi 11) Nama: Mochamad Lutfy Firmansyah (2201918614)
Tugas Personal Ke-2 (Minggu 7 / Sesi 11) Nama: Mochamad Lutfy Firmansyah (2201918614)
Tugas Personal Ke-2 (Minggu 7 / Sesi 11) Nama: Mochamad Lutfy Firmansyah (2201918614)
Jawab :
Class Stack.java :
public class Stack {
private int maxSize;
private int[] data;
private int top;
public Stack() {
maxSize = 3;
data = new int[3];
data[0] = 5;
data[1] = 3;
data[2] = 2;
}
Output :
Arrays.sort(bil);
System.out.println("Nilai Minimum = " + bil[0]);
System.out.println("Nilai Maximum = " + bil[bil.length - 1]);
}
Output :
Jawab :
Coding :
import javax.swing.JButton;
import javax.swing.JFrame;
myGui.add(btn);
}
}
try {
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/ebookshop",
"root", "");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM books");
while (rs.next()) {
int id = rs.getInt("id");
String title = rs.getString("title");
String author = rs.getString("author");
Float price = rs.getFloat("price");
int qty = rs.getInt("qty");
System.out.println("ID = " + id + " || Title = " + title +
" || Author = " + author + " || Price = " + price + " || Qty = " + qty);
}
} catch (SQLException e) {
System.out.println("SQL exception occured" + e);
}
}
Output :
Class Tugas2.java
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Scanner;
do{
System.out.println("==================================");
System.out.println("1. Volume");
System.out.println("4. Exit");
System.out.println("==================================");
System.out.print("Choice : ");
switch(choice){
case 1 :
nomor1();
break;
nomor2();
break;
case 3 :
nomor3();
break;
default :
cek = false;
break;
}while(cek == true);
int volume;
} else {
try {
if(stack.getSize() == 3){
stack.isFull();
stack.clear();
System.out.println("--------PUSH--------");
stack.push(5);
stack.push(3);
stack.push(2);
System.out.println("--------POP--------");
stack.pop();
stack.printStack();
bil[0] = input.nextInt();
bil[1] = input.nextInt();
bil[2] = input.nextInt();
Arrays.sort(bil);
public Stack() {
maxSize = 3;
data[0] = 5;
data[1] = 3;
data[2] = 2;
data[++top] = p;
System.out.println(p);
if(data[2] != 0){
data[2] = 0;
data[1] = 0;
data[0] = 0;
System.out.println("STACK IS FULL");
top = -1;
data[0] = 0;
data[1] = 0;
data[2] = 0;
return data.length;
if(data[i] != 0){
System.out.println(data[i]);
import javax.swing.JFrame;
public gui(){
this.setSize(700, 400);
myGui.setVisible(true);
myGui.add(btn);
Class jdbc.java
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
try{
} catch(ClassNotFoundException e){
try {
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/ebookshop", "root",
"");
while (rs.next()) {
int id = rs.getInt("id");
} catch (SQLException e) {