import java.util.Scanner;
public class fungsi{
int[] ha;
int[] hb;
int[] hr;
int[] hasal;
int jmlha,jmlhb,jmlhr;
Scanner inp=new Scanner(System.in);
int[] hb;
int[] hr;
int[] hasal;
int jmlha,jmlhb,jmlhr;
Scanner inp=new Scanner(System.in);
public static void main(String [] args){
fungsi madhun = new fungsi();
madhun.ia();
int pil;
Scanner inp=new Scanner(System.in);
System.out.println("============= MENU ===============");
System.out.println("1. Cek Himpunan A");
System.out.println("2. Cek Himpunan B");
System.out.println("3. Cek Fungsi");
System.out.println("==================================");
System.out.print("Pilih Menu [1-3]: ");
pil=inp.nextInt();
switch(pil){
case 1:
madhun.cha();
break;
case 2:
madhun.chb();
break;
case 3:
madhun.ir();
madhun.cf();
madhun.cr();
break;
default:
System.out.print("menu yang dipilih tidak ada");
break;
}
}
fungsi madhun = new fungsi();
madhun.ia();
int pil;
Scanner inp=new Scanner(System.in);
System.out.println("============= MENU ===============");
System.out.println("1. Cek Himpunan A");
System.out.println("2. Cek Himpunan B");
System.out.println("3. Cek Fungsi");
System.out.println("==================================");
System.out.print("Pilih Menu [1-3]: ");
pil=inp.nextInt();
switch(pil){
case 1:
madhun.cha();
break;
case 2:
madhun.chb();
break;
case 3:
madhun.ir();
madhun.cf();
madhun.cr();
break;
default:
System.out.print("menu yang dipilih tidak ada");
break;
}
}
public void ia(){
System.out.print("masukan jumlah himp A = ");
jmlha=inp.nextInt();
ha=new int[jmlha];
for(int i = 0; i<=(jmlha-1);i++){
System.out.print("himp A yang ke "+(i+1)+" = ");
ha[i]=inp.nextInt();
}
System.out.print("masukan jumlah himp B = ");
jmlhb=inp.nextInt();
hb=new int[jmlhb];
for(int i = 0; i<=(jmlhb-1);i++){
System.out.print("himp B yang ke "+(i+1)+" = ");
hb[i]=inp.nextInt();
}
}
public void cha(){
System.out.print("anggota himp A = { ");
for (int i = 0;i<(jmlha);i++){
System.out.print(ha[i]+ " ");
}
System.out.println(" } ");
}
public void chb(){
System.out.print("anggota himp B = { ");
for (int i = 0;i<(jmlhb);i++){
System.out.print(hb[i]+ " ");
}
System.out.println(" } ");
}
public void ir(){
int jmlhrmax = jmlha*jmlhb;
System.out.println("relasi maksimal adalah = "+jmlhrmax);
System.out.print("");
do{
System.out.print("masukan jumlah relasi yg terjadi = ");
jmlhr=inp.nextInt();
}while(jmlhr>jmlhrmax);
hr=new int[jmlhr];
hasal=new int[jmlhr];
System.out.println("masukan relasi yang terjadi = ");
for(int i=0; i<=(jmlhr-1);i++){
int[] temp=new int[jmlhr];
int[] temp2=new int[jmlhr];
boolean samaA= false;
boolean samaB= false;
System.out.println("relasi ke" +(i+1)+ " = ");
do{
System.out.print("masukan asal A = ");
temp[i]=inp.nextInt();
System.out.print("masukan asal B = ");
temp2[i]=inp.nextInt();
for(int j=0; j<=(jmlha-1);j++){
if(temp[i]==ha[j]){
samaA=true;
}
}
for(int j=0; j<=(jmlhb-1);j++){
if(temp2[i]==hb[j]){
samaB=true;
}
}
if(samaA==false || samaB==false){
System.out.println("anggota himpunan tidak terdapat pada a dan b");
}
if(samaA==true && samaB==true){
hr[i]=temp2[i];
hasal[i]=temp[i];
}
}while(samaA==false || samaB==false);
}
}
public void cf(){
int jmla=0;
boolean adasama=false;
for(int i=0;i<=(jmlha-1);i++){
for(int j=0;j<=(jmlhr-1);j++){
if(ha[i]==hasal[j]){
jmla++;
}
}
}
for(int i=0;i<=(jmlhr-1);i++){
for(int j=0;j<=(jmlhr-1);j++){
if(hasal[i]==hasal[j]){
adasama=true;
}
}
}
if(jmla==jmlha && adasama==false){
System.out.println("relasi yang diinput adalah fungsi");
}else{
System.out.println("relasi yang diinput bukan fungsi hanya relasi biasa");
}
}
public void cr(){
System.out.print("daerah domain = { ");
for(int i=0;i<=jmlha-1;i++){
System.out.print(ha[i]+ " ");
}
System.out.println(" } ");
System.out.print("daerah kodomain = { ");
for(int i=0;i<=jmlhb-1;i++){
System.out.print(hb[i]+ " ");
}
System.out.println(" } ");
System.out.print("daerah range = { ");
for(int i=0;i<=jmlhr-1;i++){
boolean adasama=false;
for(int j=i+1;j<=jmlhr-1;j++){
if(hr[i]==hr[j])
adasama=true;
}
if(adasama==false)System.out.print(hr[i]+" ");
}
System.out.println(" } ");
}
}
jmlhb=inp.nextInt();
hb=new int[jmlhb];
for(int i = 0; i<=(jmlhb-1);i++){
System.out.print("himp B yang ke "+(i+1)+" = ");
hb[i]=inp.nextInt();
}
}
public void cha(){
System.out.print("anggota himp A = { ");
for (int i = 0;i<(jmlha);i++){
System.out.print(ha[i]+ " ");
}
System.out.println(" } ");
}
public void chb(){
System.out.print("anggota himp B = { ");
for (int i = 0;i<(jmlhb);i++){
System.out.print(hb[i]+ " ");
}
System.out.println(" } ");
}
public void ir(){
int jmlhrmax = jmlha*jmlhb;
System.out.println("relasi maksimal adalah = "+jmlhrmax);
System.out.print("");
do{
System.out.print("masukan jumlah relasi yg terjadi = ");
jmlhr=inp.nextInt();
}while(jmlhr>jmlhrmax);
hr=new int[jmlhr];
hasal=new int[jmlhr];
System.out.println("masukan relasi yang terjadi = ");
for(int i=0; i<=(jmlhr-1);i++){
int[] temp=new int[jmlhr];
int[] temp2=new int[jmlhr];
boolean samaA= false;
boolean samaB= false;
System.out.println("relasi ke" +(i+1)+ " = ");
do{
System.out.print("masukan asal A = ");
temp[i]=inp.nextInt();
System.out.print("masukan asal B = ");
temp2[i]=inp.nextInt();
for(int j=0; j<=(jmlha-1);j++){
if(temp[i]==ha[j]){
samaA=true;
}
}
for(int j=0; j<=(jmlhb-1);j++){
if(temp2[i]==hb[j]){
samaB=true;
}
}
if(samaA==false || samaB==false){
System.out.println("anggota himpunan tidak terdapat pada a dan b");
}
if(samaA==true && samaB==true){
hr[i]=temp2[i];
hasal[i]=temp[i];
}
}while(samaA==false || samaB==false);
}
}
public void cf(){
int jmla=0;
boolean adasama=false;
for(int i=0;i<=(jmlha-1);i++){
for(int j=0;j<=(jmlhr-1);j++){
if(ha[i]==hasal[j]){
jmla++;
}
}
}
for(int i=0;i<=(jmlhr-1);i++){
for(int j=0;j<=(jmlhr-1);j++){
if(hasal[i]==hasal[j]){
adasama=true;
}
}
}
if(jmla==jmlha && adasama==false){
System.out.println("relasi yang diinput adalah fungsi");
}else{
System.out.println("relasi yang diinput bukan fungsi hanya relasi biasa");
}
}
public void cr(){
System.out.print("daerah domain = { ");
for(int i=0;i<=jmlha-1;i++){
System.out.print(ha[i]+ " ");
}
System.out.println(" } ");
System.out.print("daerah kodomain = { ");
for(int i=0;i<=jmlhb-1;i++){
System.out.print(hb[i]+ " ");
}
System.out.println(" } ");
System.out.print("daerah range = { ");
for(int i=0;i<=jmlhr-1;i++){
boolean adasama=false;
for(int j=i+1;j<=jmlhr-1;j++){
if(hr[i]==hr[j])
adasama=true;
}
if(adasama==false)System.out.print(hr[i]+" ");
}
System.out.println(" } ");
}
}
Tidak ada komentar:
Posting Komentar