0% found this document useful (0 votes)
54 views4 pages

Tugas PBO JAVA 12 Write File With Random Name New 2

The document describes 4 versions of a Java program that generates random strings to name output files. Version I generates strings with lowercase letters only. Version II generates strings with lowercase and uppercase letters. Version III generates strings that combine numbers and letters in lowercase and uppercase. Version IV generates strings with an alternating pattern of consonants and vowels. The program copies an existing project on vectors and matrices, and creates 4 new projects with the random string generation code implemented in different ways corresponding to the 4 versions described.

Uploaded by

Tito Ardiansyah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views4 pages

Tugas PBO JAVA 12 Write File With Random Name New 2

The document describes 4 versions of a Java program that generates random strings to name output files. Version I generates strings with lowercase letters only. Version II generates strings with lowercase and uppercase letters. Version III generates strings that combine numbers and letters in lowercase and uppercase. Version IV generates strings with an alternating pattern of consonants and vowels. The program copies an existing project on vectors and matrices, and creates 4 new projects with the random string generation code implemented in different ways corresponding to the 4 versions described.

Uploaded by

Tito Ardiansyah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Tugas 12a

Copy-Paste project NimNamaTugas11b (program tentang vektor dan matriks)


menjadi project
a.NimNamaTugas12a1  untuk class NamaFileAcak versi I
b.NimNamaTugas12a2  untuk class NamaFileAcak versi II
c.NimNamaTugas12a3  untuk class NamaFileAcak versi III
d.NimNamaTugas12a4  untuk class NamaFileAcak versi IV

public class Main {


/**
* @param args the command line arguments
*/
static public void main(String[] args) throws IOException
{
// instantiate input file object
FileReader file = new FileReader("matriks1.txt");
NamaFileAcak kataq=new NamaFileAcak();
// class NamaFileAcak dapat dilihat
// di bawah class main() ini
String coba_kata=kataq.buat_kata(10);
String file_out="out_";
file_out=file_out.concat(coba_kata);
file_out=file_out.concat(".txt");
System.out.println("hasil generate kata : "+file_out);
// instantiate output file object
FileWriter output = new FileWriter(file_out);
PrintWriter textFile = new PrintWriter(output);
// tokens in a line of the text file
int bil;
StreamTokenizer inputStream = new StreamTokenizer(file);
int tokenType;
// print headings
System.out.print("Contents of file"+file_out+"\n\n");
tokenType = inputStream.nextToken();
int baris;
baris=(int)inputStream.nval;
tokenType = inputStream.nextToken();
int kolom;
kolom=(int)inputStream.nval;
matriks m1=new matriks(baris,kolom);
inputStream.nextToken(); // baris berikutnya
vektor v1=new vektor(baris*kolom);
int i=0;
// boolean terus=true;
while (tokenType != StreamTokenizer.TT_EOF)
{
bil=(int)inputStream.nval;
v1.elemen(bil,i);
i++;
//inputStream.nextToken();
bil=bil*2;
//System.out.print(accuracy.format(bil)+"\t");
//textFile.println(accuracy.format(bil)+"\t");
System.out.print(bil+"\t");
if(i%kolom==0) textFile.println(bil);
else textFile.print(bil+"\t");
tokenType = inputStream.nextToken(); // karakter berikutnya
}
file.close();
output.close();
System.out.println("\n\nEND OF FILES matriks1.txt and "+file_out);
v1.tampil();
int puter=0;
for(int ii=0;ii<baris;ii++){
for(int j=0;j<kolom;j++){
m1.elemen(v1.ambil(puter), ii, j);
puter++;
}
}
m1.tampil();
}
}

Versi I  kombinasi huruf kecil saja


public class NamaFileAcak {
private String nama;
private String s[]={"a","b","c","d","e","f","g","h","i","j",
"k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z"};
//private int ukuran=s.length();
public String buat_kata(int banyak)
{
String awal,kata="a";
int pilih;
for(int i=0;i<banyak;i++)
{
pilih=(int)(Math.random()*26);
System.out.println("pilih :"+pilih);
awal=s[pilih];
if(i==0) kata=awal; else kata=kata.concat(awal);
System.out.println("kata :"+kata);
}
return kata;
}

Versi II  kombinasi huruf kecil dan


huruf besar
public class NamaFileAcak {
private String nama;
private String s[]={"a","b","c","d","e","f","g","h","i","j",
"k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z"};
//private int ukuran=s.length();
public String buat_kata(int banyak)
{
String awal,kata="a";
int pilih;
for(int i=0;i<banyak;i++)
{
pilih=(int)(Math.random()*26);
System.out.println("pilih :"+pilih);
awal=s[pilih];
if(Math.random()<0.3) awal=awal.toUpperCase();
// angka 0.3 dapat diubah-ubah sesuai
// keinginan asalkan nilainya terletak
// antara 0-1
if(i==0) kata=awal; else kata=kata.concat(awal);
System.out.println("kata :"+kata);
}
return kata;
}

}
Versi III  kombinasi angka dan
huruf (kecil dan besar)
public class NamaFileAcak {
private String nama;
private String s[]={"a","b","c","d","e","f","g","h","i","j",
"k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z"};
//private int ukuran=s.length();
public String buat_kata(int banyak)
{
String awal,kata="a";
int pilih;
for(int i=0;i<banyak;i++)
{
pilih=(int)(Math.random()*26);
System.out.println("pilih :"+pilih);
awal=s[pilih];
if(Math.random()<0.7) {
if(Math.random()<0.5) awal=awal.toUpperCase();
}
else awal=String.valueOf(pilih);
if(i==0) kata=awal;
else
kata=kata.concat(awal);

System.out.println("kata :"+kata);
}
return kata;
}

Versi IV  buatlah kombinasi huruf


kecil dan huruf besar tetapi
susunannya  konsonan+ vocal+
konsonan+ vocal dst (selang-seling)

You might also like