import java.util.Scanner;
public class Tugas_PBO{
public static void main (String[]args){
Scanner masuk=new Scanner (System.in);
int pil;
char lagi='y';
System.out.println("============================");
System.out.println(" DAFTAR RUMUS ");
System.out.println("============================");
System.out.println(" 1. Rumus Segitiga ");
System.out.println(" 2. Rumus Bujur Sangkar ");
System.out.println(" 3. Rumus Lingkaran ");
System.out.println(" 4. Rumus Persegi Panjang ");
System.out.println(" 5. Luas Bola ");
System.out.println(" 6. Volume Bola ");
System.out.println("============================");
while (lagi=='y'){
System.out.print("\nSilahkan Masukan Pilihan Rumus Yang Ingin Di Kerjakan : ");
pil=masuk.nextInt();
try{
switch (pil){
case 1:
{
String str =LuasSegitiga.bacaString();
}
break;
case 2:
{
String str = LuasBujurSangkar.bacaString();
}
break;
case 3:
{
String str = LuasLingkaran.bacaString();
}
break;
case 4:
{
String str = LuasPersegiPanjang.bacaString();
}
break;
case 5:
{
String str = LuasBola.bacaString();
}
break;
case 6:
{
String str = VolumeBola.bacaString();
}
break;
default:
System.out.println("Input Salah");
break;
}
}
catch(NumberFormatException nfe){
System.err.println("\nUuuupppss....Ada Kesalahan Input Data");
}
System.out.print("Mau Coba Rumus Lain (y/t) ? ");
String str = Lat5_BacaKeyboard.bacaString();
lagi = str.charAt(0);
if (lagi == 'Y') lagi='Y';
if (lagi == 'y') continue;
else{
System.out.println("");
System.out.println("Terima Kasih...Semoga Bermanfaat\n");
break;
}
}
}
}
3. Buat Codingan Rumusnya namun dibuatnya beda class , jadi membuat Class baru Per Rumusnya
import java.util.Scanner;
import java.io.*;
public class LuasSegitiga{
public static String bacaString(){
int alas,tinggi;
double luas;
Scanner s;
int karakter;
String string = "";
boolean selesai = false;
s=new Scanner (System.in);
System.out.println("===================");
System.out.println("RUMUS LUAS SEGITIGA");
System.out.println("===================");
System.out.print("Masukan Alas : ");
alas = s.nextInt();
System.out.print("Masukan Tinggi : ");
tinggi = s.nextInt();
System.out.println("Alas : "+alas);
System.out.println("Tinggi : "+tinggi);
System.out.println("===================");
luas =(alas* tinggi)/2;
System.out.println("Hasil Luas Segitiga (("+alas+" * " +tinggi+ ")/2) Adalah "+luas);
System.out.println(" ");
return string;
}
}
import java.util.Scanner;
import java.io.*;
public class LuasBujurSangkar {
public static String bacaString(){
int sisi,luas,kel;
String string = " ";
Scanner sc;
sc=new Scanner(System.in);
System.out.println("===================================");
System.out.println("RUMUS LUAS & KELILING BUJUR SANGKAR");
System.out.println("===================================");
System.out.print("Masukan Sisi : ");
sisi=sc.nextInt();
luas=sisi*sisi;
kel=4*sisi;
System.out.println("Sisi = "+sisi);
System.out.println("===================================");
System.out.println("Hasil Luas Bujur Sangkar ("+sisi+" * "+sisi+") Adalah "+luas);
System.out.println("Hasil Keliling Bujur Sangkar (4 * "+sisi+") Adalah "+kel);
System.out.println(" ");
return string;
}
}
import java.util.Scanner;
import java.io.*;
public class LuasLingkaran {
public static String bacaString() {
Scanner input = new Scanner(System.in);
String string="";
double phi = 3.14;
double r, luas,keliling;
System.out.println("=================================");
System.out.println("RUMUS LUAS & KELILING LINGKARAN ");
System.out.println("=================================");
System.out.print("Masukkan Panjang Jari-jari : ");
r = input.nextDouble();
luas = 0.5 * phi * r * r;
keliling = 2 * phi * r;
System.out.println("Jari-Jari = "+r);
System.out.println("=================================");
System.out.println("Hasil Luas Lingkaran (0.5 * phi * "+r+" * "+r+") Adalah " + (int)luas);
System.out.println("Hasil Keliling Lingkaran (2 * phi * "+r+") Adalah " + (int)keliling);
System.out.println("");
return string;
}
}
import java.util.Scanner;
import java.io.*;
public class LuasPersegiPanjang{
public static String bacaString (){
int panjang,lebar,luas,keliling;
Scanner S = new Scanner (System.in);
String string ="";
System.out.println("=====================================");
System.out.println("RUMUS LUAS & KELILING PERSEGI PANJANG");
System.out.println("=====================================");
System.out.print("Masukan Panjang = ");
panjang=S.nextInt();
System.out.print("Masukan Lebar = ");
lebar=S.nextInt();
luas = panjang*lebar;
keliling = 2*(panjang+lebar);
System.out.println("Panjang = "+panjang);
System.out.println("Lebar = "+lebar);
System.out.println("======================================");
System.out.println("Hasil Luas Persegi Panjang ("+panjang+" * "+lebar+") Adalah "+luas);
System.out.println("Hasil Keliling Persegi Panjang (2 * ("+panjang+" + "+lebar+")) Adalah "+keliling);
System.out.println("");
return string;
}
}
import java.util.Scanner;
import java.io.*;
public class LuasBola {
public static String bacaString() {
String string ="";
Scanner input = new Scanner (System.in);
System.out.println("===============");
System.out.println("RUMUS LUAS BOLA");
System.out.println("===============");
System.out.print("Masukan Jari-Jari : ");
int r = input.nextInt();
double phi = 3.14;
double luasbola = phi*r*r;
System.out.println("Phi = "+phi);
System.out.println("Jari-Jari : "+r);
System.out.println("===================");
System.out.println("Hasil Luas Bola (phi * "+r+" * "+r+") = "+luasbola);
System.out.println("");
return string;
}
}
import java.util.Scanner;
import java.io.*;
public class VolumeBola {
public static String bacaString(){
String string="";
System.out.println("=========================");
System.out.println(" RUMUS VOLUME BOLA ");
System.out.println("=========================");
System.out.print("Masukkan Jari-Jari Bola : ");
Scanner input = new Scanner(System.in);
double jari = input.nextDouble();
double hasil = jari*jari*jari*22/7*4/3;
System.out.println("Jari-Jari Bola : "+jari);
System.out.println("===================");
System.out.println("Hasil Volume Bola ("+jari+" * "+jari+" * "+jari+" * 22/7 * 4/3) Adalah " +hasil) ;
System.out.println("");
return string;
}
}
Jadi Hasil Semuanya akan seperti :
|
Tampilan di Blue J |