JAVASSIGN MUB3
JAVASSIGN MUB3
Programming in
Java
Faculty: Dr.DEEPIKA S
1. import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.FileWriter;
public StudentFileCreator() {
frame.setLayout(new FlowLayout());
saveStudentInfo();
});
frame.add(rollNumberLabel);
frame.add(rollNumberField);
frame.add(nameLabel);
frame.add(nameField);
frame.add(marksLabel);
frame.add(marksField);
tt
tt
tt
ti
ti
ti
tt
ti
ti
Mohammed Mubasheer 22MMI0013
frame.add(saveBu on);
frame.setDefaultCloseOpera on(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setVisible(true);
return;
leWriter.write(studentInfo);
rollNumberField.setText("");
nameField.setText("");
marksField.setText("");
} catch (IOExcep on e) {
new StudentFileCreator();
fi
ti
ti
ti
ti
ti
ti
fi
ti
tt
ti
fi
fi
ti
Mohammed Mubasheer 22MMI0013
}
});
import java.io.FileReader;
String line;
double sum = 0;
try {
sum += number;
} catch (NumberFormatExcep on e) {
} catch (IOExcep on e) {
}
ff
fi
ti
ff
ti
ti
ff
ti
fi
fi
Mohammed Mubasheer 22MMI0013
3. import java.io.FileInputStream;
int byteRead;
System.out.print((char) byteRead);
} } catch (IOExcep on e) {
4. import java.io.*;
try {
randomAccessFile.seek(10);
randomAccessFile.writeUTF("New Data");
dataInputStream.close();
randomAccessFile.close();
fi
fi
ti
ti
fi
ti
ti
fi
fi
fi
fi
fi
Mohammed Mubasheer 22MMI0013
} catch (IOExcep on e) {
e.printStackTrace();
5. import java.io.*;
dataOutputStream.writeInt(42);
dataOutputStream.writeDouble(3.14159);
dataOutputStream.writeBoolean(true);
} catch (IOExcep on e) {
e.printStackTrace();
} catch (IOExcep on e) {
e.printStackTrace();
class Employee {
this.id = id;
this.salary = salary;
this.name = name;
this.address = address;
@Override
return "ID: " + id + ", Salary: " + salary + ", Name: " + name + ", Address: " + address;
}}
String line;
if (parts.length == 4) {
int id = Integer.parseInt(parts[0].trim());
} else {
}}
} catch (IOExcep on e) {
e.printStackTrace(); }}}
this.id = id;
this.name = name;
oos.writeObject(student);
} catch (IOExcep on e) {
e.printStackTrace();
e.printStackTrace(); } } }
reversedString.append(reversedWord).append(" ");
word = word.toLowerCase();
ti
ti
ti
ti
ti
ti
Mohammed Mubasheer 22MMI0013
if (wordCount.containsKey(word)) {
} else {
wordCount.put(word, 1);
if (entry.getValue() > 1) {
} }}}
int count = 0;
count++;
System.out.println("Substring '" + substring + "' appears " + count + " mes in the input string.");
}
ti
ti
Mohammed Mubasheer 22MMI0013
C. Checking if a String is a Palindrome:
public class PalindromeChecker {
if (isPalindrome(input)) {
} else {
int le = 0;
if (str.charAt(le ) != str.charAt(right)) {
return false;
le ++;
right--;
return true;
9. import java.io.*;
String line;
if (!word.isEmpty()) {
} catch (IOExcep on e) {
e.printStackTrace();
writer.newLine();
} catch (IOExcep on e) {
e.printStackTrace();
}
tt
ff
ff
ti
ti
ti
tt
ti
ti
tt
tt
tt
ff
ff
ti
Mohammed Mubasheer 22MMI0013
System.out.println("Word counts have been wri en to " + outputFileName);
import java.io.FileReader;
String line;
textContent.append(line).append("\n");
int mostCommonWordCount = 0;
mostCommonWord = entry.getKey();
fi
ff
ti
ti
ff
ti
ff
tt
fi
Mohammed Mubasheer 22MMI0013
mostCommonWordCount = entry.getValue();
System.out.println(word);
} catch (IOExcep on e) {
e.printStackTrace();
import java.io.FileOutputStream;
int bytesRead;
} catch (IOExcep on e) {
e.printStackTrace();
try {
System.out.print("Enter the name of the text le you want to read (e.g., sample.txt): ");
String line;
System.out.println(line);
} leReader.close();
ff
ff
ti
ti
fi
fi
ff
ti
fi
ti
fi
fi
ti
ff
ti
ff
ff
fi
ff
fi
fi
fi
ti
ti
fi
Mohammed Mubasheer 22MMI0013
} catch (FileNotFoundExcep on e) {
} catch (IOExcep on e) {
} nally {
try {
reader.close();
} catch (IOExcep on e) {
e.printStackTrace();
}
fi
ti
ti
ti
fi