Advertisement
cynthiarez

REMINDER / PRACTICE = PRINTWRITER/FILEREADER (NO CODIGS)

Sep 24th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. package NewJava2;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.io.PrintWriter;
  5. import java.util.Scanner;
  6.  
  7. import javax.swing.JOptionPane;
  8.  
  9. public class labquiz {
  10.  
  11. public static void main(String[] args) throws FileNotFoundException {
  12.  
  13. PrintWriter outfile = new PrintWriter("wt.txt");
  14.  
  15. String name, searchname,fname;
  16. int weight;
  17.  
  18. do{
  19. name = JOptionPane.showInputDialog("Enter name");
  20. weight = Integer.parseInt(JOptionPane.showInputDialog("Enter weight"));
  21.  
  22. outfile.println(name+":"+weight);
  23.  
  24. }
  25. while (JOptionPane.showConfirmDialog(null,"Add more entries?")==0);
  26.  
  27. outfile.close();
  28.  
  29.  
  30.  
  31.  
  32. searchname = JOptionPane.showInputDialog("Search for name");
  33. Scanner infile = new Scanner (new FileReader("wt.txt"));
  34. infile.useDelimiter(":");
  35. boolean found = false;
  36.  
  37. while(infile.hasNext() && !found){
  38.  
  39. fname = infile.next();
  40.  
  41. infile.nextLine();
  42.  
  43. if (fname.equalsIgnoreCase(searchname)){
  44.  
  45. if (weight<50){
  46. JOptionPane.showMessageDialog(null, fname +" "+ weight + " EAT MORE!");
  47.  
  48. }
  49.  
  50. else if (weight==50 && weight<=80){
  51. JOptionPane.showMessageDialog(null, fname +" "+ weight + " STAY HEALTHY!");
  52.  
  53. }
  54.  
  55. if (weight>80){
  56. JOptionPane.showMessageDialog(null, fname +" "+ weight + " LET'S EXCERCISE");
  57.  
  58. }
  59. found = true;
  60. }
  61.  
  62. }
  63. infile.close();
  64. if (!found){
  65. JOptionPane.showMessageDialog(null, " NO SUCH TAO");
  66.  
  67. }
  68. }
  69.  
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement