Notes
Notes - notes.io |
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
class Barang {
int kode;
String nama_barang;
int jumlah;
double diskon;
double harga;
public Barang(int kode, String nama_barang, int jumlah, double diskon, double harga) {
this.kode = kode;
this.nama_barang = nama_barang;
this.jumlah = jumlah;
this.diskon = diskon;
this.harga = harga;
}
}
class Node {
Barang barang;
Node next;
public Node(Barang barang) {
this.barang = barang;
this.next = null;
}
}
public class Penjualan {
Node head;
public void tambahSimpul(Barang barang) {
Node new_node = new Node(barang);
if (head == null) {
head = new_node;
head.next = head;
} else {
Node current = head;
Node prev = null;
do {
if (current.barang.nama_barang.compareTo(barang.nama_barang) > 0) {
break;
}
prev = current;
current = current.next;
} while (current != head);
new_node.next = current;
if (prev != null) {
prev.next = new_node;
} else {
Node last = head;
while (last.next != head) {
last = last.next;
}
last.next = new_node;
head = new_node;
}
}
}
public void hapusDiskonNol() {
if (head == null) {
return;
}
Node current = head;
Node prev = null;
Node first = head;
do {
if (current.barang.diskon == 0) {
if (current == head) {
head = current.next;
}
if (prev != null) {
prev.next = current.next;
}
if (current == first) {
first = current.next;
}
} else {
prev = current;
}
current = current.next;
} while (current != first);
}
public double rataRataHarga() {
Node current = head;
double totalHarga = 0;
int count = 0;
do {
totalHarga += (current.barang.harga - (current.barang.diskon / 100) * current.barang.harga) * current.barang.jumlah;
count++;
current = current.next;
} while (current != head);
return count > 0 ? totalHarga / count : 0;
}
public void tampilkanDataDiatasRataRata() {
Node current = head;
double rataRata = rataRataHarga();
do {
double totalHarga = (current.barang.harga - (current.barang.diskon / 100) * current.barang.harga) * current.barang.jumlah;
if (totalHarga > rataRata) {
System.out.println("Kode: " + current.barang.kode + ", Nama Barang: " + current.barang.nama_barang
+ ", Harga: " + current.barang.harga + ", Diskon: " + current.barang.diskon + ", Jumlah: "
+ current.barang.jumlah);
}
current = current.next;
} while (current != head);
}
public double totalHarga() {
Node current = head;
double totalHarga = 0;
do {
totalHarga += (current.barang.harga - (current.barang.diskon / 100) * current.barang.harga) * current.barang.jumlah;
current = current.next;
} while (current != head);
return totalHarga;
}
public static void main(String[] args) {
Penjualan penjualan = new Penjualan();
Barang barang1 = new Barang(1000, "Kalender", 1, 10, 20000);
Barang barang2 = new Barang(1001, "Rak Buku", 20, 60, 50000);
Barang barang3 = new Barang(1002, "Baskom", 100, 0, 1000);
penjualan.tambahSimpul(barang1);
penjualan.tambahSimpul(barang2);
penjualan.tambahSimpul(barang3);
System.out.println("Data sebelum penghapusan diskon 0%:");
penjualan.tampilkanDataDiatasRataRata();
penjualan.hapusDiskonNol();
System.out.println("nData setelah penghapusan diskon 0%:");
penjualan.tampilkanDataDiatasRataRata();
double totalHarga = penjualan.totalHarga();
System.out.println("nTotal Harga: " + totalHarga);
}
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team