main class
coding rumus persegi
coding hasil lingkaran
hasilnya
koding segitiga
hasilnya
koding persegi panjang
hasilnya
sekian terima kasih semoga bermanfaat
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tugasclass;
import java.util.Scanner;
/**
*
* @author xXbStarXx
*/
public class Tugasclass {
Scanner input=new Scanner(System.in);
int pil;
double ss, jr2, als, tggi, ls, p, l;
public int pil(){
if(pil==1){
System.out.print("input nilai ss= ");
ss=input.nextDouble();
classpersegi prsg =new classpersegi(ss);
System.out.println("ls persegi = "+ prsg.getLuas());
}else if(pil==2){
System.out.print("input nilai jari-jari = ");
jr2=input.nextDouble();
classlingkaran lngkrn=new classlingkaran(jr2);
System.out.println("ls lingkaran = "+lngkrn.getLuas());
}else if(pil==3){
System.out.print("input nilai als = ");
als=input.nextDouble();
System.out.print("input nilai tggi = ");
tggi=input.nextDouble();
classsegitiga sgtg=new classsegitiga(als, tggi);
System.out.println("ls segitiga = "+sgtg.getLuas());
}
else {
System.out.print("input nilai panjang = ");
p=input.nextDouble();
System.out.print("input nilai lebar = ");
l=input.nextDouble();
classpersegipanjang perjang=new classpersegipanjang(p, l);
System.out.println("Luas Persegi Panjang = "+perjang.getLuas());
}
return pil;
}
public static void main(String[] args) {
Tugasclass BD=new Tugasclass();
Scanner input=new Scanner(System.in);
System.out.println("bangun datar"+ "\n++++++++++++++++++");
System.out.println("1.Persegi\n2.Lingkaran\n3.Segitiga\n4.Persegi Panjang\nPilih Bangun Datar");
BD.pil=input.nextInt();
BD.pil();
}
}
hasilnyacoding rumus persegi
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tugasclass;
/**
*
* @author xXbStarXx
*/
public class classpersegi {
double ss;
public classpersegi(double ss){
this.ss = ss;
}
public double getLuas(){
double ls;
ls=ss*ss;
return ls;
}
}
hasilnyacoding hasil lingkaran
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tugasclass;
/**
*
* @author xXbStarXx
*/
public class classlingkaran {
double jr2;
public classlingkaran(double jr2){
this.jr2=jr2;
}
public double getLuas(){
double ls;
ls=3.14*(jr2*jr2);
return ls;
}
}
hasilnya
koding segitiga
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tugasclass;
/**
*
* @author xXbStarXx
*/
public class classsegitiga {
double als, tggi;
public classsegitiga(double als, double tggi){
this.als = als;
this.tggi = tggi;
}
public double getLuas(){
double ls;
ls=(0.5*als)*tggi;
return ls;
}
}
hasilnya
koding persegi panjang
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tugasclass;
/**
*
* @author xXbStarXx
*/
public class classpersegipanjang {
double p, l;
public classpersegipanjang(double p, double l){
this.p = p;
this.l = l;
}
public double getLuas(){
double ls;
ls=p*l;
return ls;
}
}
hasilnya
sekian terima kasih semoga bermanfaat
Comments
Post a Comment