SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.util.*; | |
| 2 | import java.io.*; | |
| 3 | ||
| 4 | public class Dec2015 {
| |
| 5 | public static void main(String args[]) {
| |
| 6 | ||
| 7 | try {
| |
| 8 | Scanner s = new Scanner(new File("software.txt"));
| |
| 9 | PrintWriter tulis = new PrintWriter("MSOffice.txt");
| |
| 10 | ||
| 11 | System.out.println("Details of software transaction\nSoftware Name\tTotal Price(RM)");
| |
| 12 | tulis.println("Details of software transaction\nSoftware Name\tTotal Price(RM)");
| |
| 13 | double grand=0; | |
| 14 | double grandms=0; | |
| 15 | while(s.hasNextLine()) {
| |
| 16 | String content = s.nextLine(); | |
| 17 | ||
| 18 | String isi[] = content.split(";");
| |
| 19 | ||
| 20 | double total = Integer.parseInt(isi[1])*Double.parseDouble(isi[2]); | |
| 21 | System.out.println(isi[0] + "\t" + total); | |
| 22 | ||
| 23 | grand+=total; | |
| 24 | ||
| 25 | ||
| 26 | if( isi[0].substring(0,9).equals("MS Office") ){
| |
| 27 | tulis.println(isi[0] + "\t" + total); | |
| 28 | grandms+=total; | |
| 29 | } | |
| 30 | ||
| 31 | } | |
| 32 | System.out.println("\tGRAND TOTAL\t" + grand);
| |
| 33 | tulis.println("\tGRAND TOTAL\t" + grandms);
| |
| 34 | tulis.close(); | |
| 35 | ||
| 36 | } | |
| 37 | catch(FileNotFoundException e) {
| |
| 38 | System.out.println(e); | |
| 39 | } | |
| 40 | catch(NullPointerException e){
| |
| 41 | System.out.println(e); | |
| 42 | } | |
| 43 | catch(IOException e){
| |
| 44 | System.out.println(e); | |
| 45 | } | |
| 46 | } | |
| 47 | } |