Last active
October 8, 2015 15:59
-
-
Save dheshanm/63aa5d816aa3e904907b to your computer and use it in GitHub Desktop.
String Data in a .txt File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package starting.java.tutorials; | |
| import java.util.*; | |
| import java.io.*; | |
| /** | |
| * Created by Dheshan M (@D-codex) on 10/8/2015. | |
| */ | |
| public class MarksStorage { | |
| public static void main(String Args[])throws IOException{ | |
| String phy,chem,math,eng,cs,Exam,totals; | |
| int c,i,j,m,n; | |
| int ph,ch,ma,en,co,total,totalp; | |
| Scanner in=new Scanner(System.in); | |
| System.out.println("Enter 0 to Input marks to Database ;"); | |
| System.out.println("Enter 1 to view Records"); | |
| c=in.nextInt(); | |
| switch(c){ | |
| case 0: | |
| FileWriter fr=new FileWriter("MarksDatabase.txt",true); | |
| BufferedWriter br=new BufferedWriter(fr); | |
| PrintWriter pw=new PrintWriter(br); | |
| System.out.print("Enter your Examination name :"); | |
| Exam=in.next(); | |
| System.out.print("Enter Your Physics Mark :"); | |
| phy=in.next(); | |
| ph=Integer.parseInt(phy); | |
| System.out.print("Enter your Chemistry Mark :"); | |
| chem=in.next(); | |
| ch=Integer.parseInt(chem); | |
| System.out.print("Enter your Mathematics Mark :"); | |
| math=in.next(); | |
| ma=Integer.parseInt(math); | |
| System.out.print("Enter your English Mark :"); | |
| eng=in.next(); | |
| en=Integer.parseInt(eng); | |
| System.out.print("Enter your Computer Science Mark :"); | |
| cs=in.next(); | |
| co=Integer.parseInt(cs); | |
| total=ph+ch+ma+en+co; | |
| pw.println(Exam); | |
| pw.println(phy); | |
| pw.println(chem); | |
| pw.println(math); | |
| pw.println(eng); | |
| pw.println(cs); | |
| pw.println(total); | |
| pw.close(); | |
| br.close(); | |
| fr.close(); | |
| break; | |
| case 1: | |
| System.out.println("Accessing Marks Database... Please wait while processing records.... "); | |
| Scanner s=new Scanner(new File("MarksDatabase.txt")); | |
| System.out.println("Connection Established Successfully !! Printing Results..... \n\n\n"); | |
| System.out.println("Examination Name Physics Chemistry Mathematics English Comp. Total"); | |
| while(s.hasNext()){ | |
| Exam=s.next(); | |
| phy=s.next(); | |
| chem=s.next(); | |
| math=s.next(); | |
| eng=s.next(); | |
| cs=s.next(); | |
| totals=s.next(); | |
| System.out.println(Exam+" "+phy+" "+chem+" "+math+" "+eng+" "+cs+" "+totals); | |
| } | |
| System.out.println("\n\n"+"_______________END______OF_____RESULT________________"); | |
| s.close(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment