Hall details

 HALL,JAVA:

import java.io.*;
import java.util.*;
public class Hall {
	private String name;
    private String contact;
    private Double costPerDay;
    private String owner;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getContact() {
		return contact;
	}
	public void setContact(String contact) {
		this.contact = contact;
	}
	public Double getCostPerDay() {
		return costPerDay;
	}
	public void setCostPerDay(Double costPerDay) {
		this.costPerDay = costPerDay;
	}
	public String getOwner() {
		return owner;
	}
	public void setOwner(String owner) {
		this.owner = owner;
	}
	public Hall(String name, String contact, Double costPerDay, String owner) {
		super();
		this.name = name;
		this.contact = contact;
		this.costPerDay = costPerDay;
		this.owner = owner;
	}
	public static void writeHallDetails(List<Hall> halls)throws IOException{
        FileWriter fi = new FileWriter("hall.csv",false);
        //Your code here
        for(int size=0;size<halls.size();size++)
        {
            Hall hall=(Hall)halls.get(size);
            fi.write(hall.getName()+","+hall.getContact()+","+hall.getCostPerDay()+","+hall.getOwner()+"\n");
        }
        fi.close();
    }
}



MAIN.JAVA:

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;




public class Main {
    public static void main(String[] args) throws IOException {
  
        Scanner in=new Scanner(System.in);
        ArrayList<Hall> halls=new ArrayList<>();




        System.out.println("Enter the number of halls: ");
        int n=in.nextInt();




        String[] array=new String[n];
        in.nextLine();   
        
        for(int i=0; i<n; i++){
            //String str= in.nextLine();              
            array[i]=in.nextLine();
            String data[]=array[i].split(",");
            halls.add(new Hall(data[0],data[1],Double.parseDouble(data[2]),data[3]));
        }
        
        Hall.writeHallDetails(halls);
        
    }
}


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.