Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package NewJava2;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.PrintWriter;
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- public class labquiz {
- public static void main(String[] args) throws FileNotFoundException {
- PrintWriter outfile = new PrintWriter("wt.txt");
- String name, searchname,fname;
- int weight;
- do{
- name = JOptionPane.showInputDialog("Enter name");
- weight = Integer.parseInt(JOptionPane.showInputDialog("Enter weight"));
- outfile.println(name+":"+weight);
- }
- while (JOptionPane.showConfirmDialog(null,"Add more entries?")==0);
- outfile.close();
- searchname = JOptionPane.showInputDialog("Search for name");
- Scanner infile = new Scanner (new FileReader("wt.txt"));
- infile.useDelimiter(":");
- boolean found = false;
- while(infile.hasNext() && !found){
- fname = infile.next();
- infile.nextLine();
- if (fname.equalsIgnoreCase(searchname)){
- if (weight<50){
- JOptionPane.showMessageDialog(null, fname +" "+ weight + " EAT MORE!");
- }
- else if (weight==50 && weight<=80){
- JOptionPane.showMessageDialog(null, fname +" "+ weight + " STAY HEALTHY!");
- }
- if (weight>80){
- JOptionPane.showMessageDialog(null, fname +" "+ weight + " LET'S EXCERCISE");
- }
- found = true;
- }
- }
- infile.close();
- if (!found){
- JOptionPane.showMessageDialog(null, " NO SUCH TAO");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement