Senin, 20 Maret 2017

TUGAS KE-5 "Array" Oleh Rofiana Manullang

Latihan/Tugas

1. Sebuah perusahaan ayam goreng dengan nama “GEROBAK FRIED CHICKEN” yang
telah lumayan banyak pelanggannya, ingin dibantu dibuatkan program untuk
membantu kelancaran usahaannya. “GEROBAK FRIED CHICKEN” mempunyai
daftar harga ayam sebagai berikut :

Banyak Jenis : ... <diinput>
Jenis Ke - ... <proses counter>
Jenis Potong [D/P/S] : ... <diinput>
Banyak Potong : ... <diinput>
<<Terus berulang tergantung Banyak Jenis>>





PENYELESAIAN


Source Code :

import java.util.*;

class  GEROBAKFRIEDCHICKEN
{

    public static void main (String[] args) throws Exception
    {
     String[] kode = new String[10];
        String[] jenis = new String[10];
        int i,j;
        double jumlah=0 ,pjk=0, total=0;
        int[] potong = new int[10];
        int[] harga = new int[10];
        int[] jml = new int[10];
   
        Scanner input = new Scanner(System.in);
        
     System.out.println("GEROBAK FRIED CHICKEN");
     System.out.println("---------------------");
     System.out.println("Kode   Jenis   Harga ");
     System.out.println("---------------------");
     System.out.println("D      Dada    Rp.2500");
     System.out.println("P      Paha    Rp.2000");
     System.out.println("S      Sayap   Rp.1500");
     System.out.println("---------------------");
   
     System.out.print("Banyak Jenis : ");
     j=input.nextInt();
   
     for(i=0; i<j; i++)
     {
     System.out.println("\nJenis Ke - " + (i+1));
     System.out.print("Jenis Potong [D/P/S] : ");
     kode[i]= input.next();
   
            if ("D".equals(kode[i]) || "d".equals(kode[i]))   
            {
            jenis[i]="Dada";
            harga[i]=2500;
            }
            else if ("P".equals(kode[i]) || "p".equals(kode[i]))
            {
            jenis[i]="Paha";
            harga[i]=2000;
            }
            else 
            {
            jenis[i]="Sayap";
            harga[i]=1500;
            }
              
   
     System.out.print("Banyak Potong        : ");
     potong[i] = input.nextInt();
               
            jml[i]=harga[i]*potong[i];
     }
   
     System.out.println("\n\tGEROBAK FRIED CHICKEN            ");
     System.out.println("---------------------------------------------");
     System.out.println("No.\tJenis\tHarga\tBanyak\tJumlah");
     System.out.println("\tPotong\tSatuan\tBeli\tHarga ");
     System.out.println("---------------------------------------------");
       
        for(i=0;i<j;i++)
        {
            System.out.println(+(i+1)+ "\t" +jenis[i]+ "\t" +harga[i]+ "\t" +potong[i]+ "\t\t" +jml[i]);
            jumlah=jumlah+jml[i];
        }
       
        System.out.println("---------------------------------------------");
       
       
        pjk=jumlah*0.1;
        total=jumlah+pjk;
       
        System.out.println("\tJumlah Bayar\t\t\t" +jumlah);
        System.out.println("\tPajak 10%\t\t\t\t" +pjk);
        System.out.println("\tTotal Bayar\t\t\t\t" +total);
   
    }
       
}

Output :






SEKIAN POSTINGAN SAYA UNTUK TUGAS ARRAY :-)

Minggu, 19 Maret 2017

TUGAS KE-4 "LOOPING" Oleh Rofiana Manullang


=====Latihan / Tugas=====

a. Buatlah program untuk menghitung 10 deret bilangan genap dengan hasilnya :
2 + 4 + 6 + 8 + 10 + 12 + 14 + 16 + 18 + 20 = 110

b. Buatlah program untuk menghitung 10 deret bilangan ganjil dengan hasilnya :
1 + 3 + 5 + 7 + 9 + 11 + 13 + 15 + 17 + 19 = 100

c. Buatlah program untuk menampilkan deret fibonanci, seperti dibawah ini :
1, 1, 2, 3, 5, 8, 13, 21

d. Buatlah program untuk menampilkan bilangan prima, seperti dibawah ini :
2, 3, 5, 7, 11, 13, 17, 19





=====Source code Latihan =====


A.Source Code :

    import java.util.Scanner;
public class genap {

public static void main(String[] args) {
@SuppressWarnings({ "resource", "unused" })
Scanner sclim = new Scanner(System.in);
System.out.println("Deret Bilangan Genap antara 2 - 20 = ");
System.out.println("-----");
int sum = 0, number = 1;
while(number<=20){
    if((number!=1)&&(number%2==0))
        sum= sum + number;
    if((number!=1)&&(number%2==0))
        System.out.println(number);
    number++;
        }

System.out.println("-----");

System.out.printf("Jumlah = %d " , sum);
}
}



B.Source Code :

      import java.util.Scanner;
public class ganjil {

public static void main(String[] args) {
@SuppressWarnings({ "resource", "unused" })
Scanner sclim = new Scanner(System.in);
System.out.println("Deret Bilangan Ganjil antara 1 - 19 = ");
System.out.println("-------");
int sum = 0, number = 1;
while(number<=19){
    if((number!=0)&&(number%2==1))
        sum= sum + number;
    if((number!=0)&&(number%2==1))
        System.out.println(number);
    number++;
        }

System.out.println("-------");

System.out.printf("Jumlah = %d " , sum);
}
}


C.Source Code :


 import javax.swing.JOptionPane;
public class Fibonacci
{
public static void main(String[]args)
{
  int a = Integer.parseInt(JOptionPane.showInputDialog("Masukkan nilai awal Deret Fibonacci"));
  int b = a;
  int c = Integer.parseInt(JOptionPane.showInputDialog("Masukkan deret Fibonacci yang Anda Inginkan: "));
  int d = c-1;
  int e = 1;
  System.out.print(a + " ");
  while(e <=d)
  {
   System.out.print(a +" ");
   a = a+b;
   b = a-b;
   e++;
  }
}
}



D.Source Code :

public class BilPrima {
 public static void main(String args[]){
 int max = 19;
 boolean isPrima = false;

 for(int i=2; i<=max; i++){
 isPrima = true;
 for(int j=2; j<i; j++){
 if(i % j == 0){
 isPrima = false;
 break;
 }
 }
 if(isPrima){
 System.out.print(i +" ");
 }
 }
 }
}




"SEKIAN POST BLOG SAYA HARI INI"