package java_file;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
import java.io.File;
/**
*
* @author bluejundi
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
// TODO code application logic here
throws FileNotFoundException {
double unitPrice, quantity, total;
PrintStream diskWriter = new PrintStream("databarang.txt");
Scanner diskScanner = new Scanner(new File("cookedData.txt"));
/* import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
import java.io.File;
/**
*
* @author bluejundi
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
// TODO code application logic here
throws FileNotFoundException {
double unitPrice, quantity, total;
PrintStream diskWriter = new PrintStream("databarang.txt");
Scanner diskScanner = new Scanner(new File("cookedData.txt"));
unitPrice = 1000;
quantity = 5;
total = unitPrice * quantity;
//menulis ke file
diskWriter.print(unitPrice+" ");
diskWriter.print(quantity+" ");
diskWriter.println(total);
//membaca dr file
unitPrice = diskScanner.nextDouble();
quantity = diskScanner.nextDouble();
total = diskScanner.nextDouble();
System.out.println("Harga satuan : "+unitPrice);
System.out.println("Jumlah barang: "+quantity);
System.out.println("Total harga : "+total);
*/ //membaca dan menulis
int npm;
String nama = new String("");
double ipk;
diskWriter = new PrintStream("mhs.txt"); //buat file
int i;
Scanner sc = new Scanner(System.in);
System.out.print("Jumlah data = ");
i = sc.nextInt();
do
{
System.out.print("NPM = ");
npm = sc.nextInt();
System.out.print("Nama = ");
nama = sc.next();
System.out.print("IPK = ");
ipk = sc.nextDouble();
diskWriter.println(npm + " " + nama + " " + ipk);
i--;
}
while(i>0);
System.out.println("Isi File:");
diskScanner = new Scanner(new File("mhs.txt"));
while (diskScanner.hasNext())
{
npm = diskScanner.nextInt();
nama = diskScanner.next();
ipk = diskScanner.nextDouble();
System.out.println("["+npm+"] "+nama+" ("+ipk+")");
}
}
}
String nama = new String("");
double ipk;
diskWriter = new PrintStream("mhs.txt"); //buat file
int i;
Scanner sc = new Scanner(System.in);
System.out.print("Jumlah data = ");
i = sc.nextInt();
do
{
System.out.print("NPM = ");
npm = sc.nextInt();
System.out.print("Nama = ");
nama = sc.next();
System.out.print("IPK = ");
ipk = sc.nextDouble();
diskWriter.println(npm + " " + nama + " " + ipk);
i--;
}
while(i>0);
System.out.println("Isi File:");
diskScanner = new Scanner(new File("mhs.txt"));
while (diskScanner.hasNext())
{
npm = diskScanner.nextInt();
nama = diskScanner.next();
ipk = diskScanner.nextDouble();
System.out.println("["+npm+"] "+nama+" ("+ipk+")");
}
}
}
No comments:
Post a Comment