Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Program {
- public static void main(String[] args) {
- try {
- File inputFile = new File("data.txt");
- Scanner reader = new Scanner(inputFile);
- File outputFile = new File("out.txt");
- PrintWriter writer = new PrintWriter(outputFile);
- ArrayList<Imot> imoti = new ArrayList<Imot>();
- while (reader.hasNextLine()) {
- String name = reader.nextLine();
- String address = reader.nextLine();
- int number = Integer.parseInt(reader.nextLine());
- double price = Double.parseDouble(reader.nextLine());
- imoti.add(new Imot(name, address, number, price));
- }
- int minPriceIndex = 0;
- for (int i = 1; i < imoti.size(); i++) {
- if (imoti.get(i).getPrice() < imoti.get(minPriceIndex).getPrice()) {
- minPriceIndex = i;
- }
- }
- System.out.println("Lower price: ");
- System.out.println("Name: " + imoti.get(minPriceIndex).getName());
- System.out.println("Address: " + imoti.get(minPriceIndex).getAddress());
- System.out.println("Number: " + imoti.get(minPriceIndex).getNumber());
- System.out.println("Price: " + imoti.get(minPriceIndex).getPrice() + " lv");
- writer.println("Lower price: ");
- writer.println("Name: " + imoti.get(minPriceIndex).getName());
- writer.println("Address: " + imoti.get(minPriceIndex).getAddress());
- writer.println("Number: " + imoti.get(minPriceIndex).getNumber());
- writer.println("Price: " + imoti.get(minPriceIndex).getPrice() + " lv");
- reader.close();
- writer.close();
- } catch (FileNotFoundException e) {
- System.out.println("File is not found");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement