ASS5
ASS5
ASS5
Assignment 5
import java.io.*;
if (args.length < 2) {
return;
int b;
out.write(b);
Output:
import java.io.*;
if (args.length < 1) {
return;
String line;
lines++;
words += wordsArray.length;
letters += word.length();
Output:
Number of letters: 70
Number of words: 14
Number of lines: 3
For the rest of the programs, let me add the output statements.
12202040501019 Dharmik Rabadiya
3]Program to write student details into a file and display details of students who stay in AHMEDABAD:
import java.io.*;
import java.util.*;
String name;
int age;
String gender;
String city;
String mobNo;
public Student(String name, int age, String gender, String city, String mobNo) {
this.name = name;
this.age = age;
this.gender = gender;
this.city = city;
this.mobNo = mobNo;
@Override
return "Name: " + name + ", Age: " + age + ", Gender: " + gender + ", City: " + city + ", Mobile No: " + mobNo;
out.writeObject(student);
} catch (IOException e) {
e.printStackTrace();
while (true) {
if (student.city.equals("AHMEDABAD")) {
System.out.println(student);
} catch (EOFException e) {
e.printStackTrace();
Output:
Name: John, Age: 20, Gender: Male, City: AHMEDABAD, Mobile No: 1234567890
Name: Bob, Age: 21, Gender: Male, City: AHMEDABAD, Mobile No: 5678901234
4]Program that takes filename and word as input and displays the occurrence of that word in a file:
12202040501019 Dharmik Rabadiya
import java.io.*;
if (args.length < 2) {
return;
int count = 0;
String line;
if (w.equals(word)) {
count++;
Output:
import java.io.*;
if (args.length < 1) {
return;
listFiles(directory);
if (files != null) {
if (file.isDirectory()) {
listFiles(file);
} else {
System.out.println(file.getAbsolutePath());
Output:
/path/to/directory/file1.txt
/path/to/directory/subdirectory/file2.txt
/path/to/directory/subdirectory/subsubdirectory/file3.txt
12202040501019 Dharmik Rabadiya
6]Program to calculate the average temperature for every year from a file containing year, month, day, and temperature
separated by commas:
import java.io.*;
import java.util.*;
if (args.length < 1) {
return;
String line;
if (!yearTemperatures.containsKey(year)) {
yearTemperatures.get(year).add(temp);
double sum = 0;
sum += temp;
Output: