Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.PrintWriter;
- import java.util.*;
- public class DailyTemperatures {
- private List<Temperature> dnevnaTemp;
- public DailyTemperatures(){
- this.dnevnaTemp =new ArrayList<>();
- }
- public void addTemperature(Temperature t){
- dnevnaTemp.add(t);
- }
- public void readTemperatures(InputStream inputStream){
- Scanner scan=new Scanner(inputStream);
- while(scan.hasNextLine()) {
- String s = scan.nextLine();
- String[] split = s.split("\\s");
- int day = Integer.parseInt(split[0]);
- Temperature temp = new Temperature(day);
- temp.setWhich(split[0].charAt(split.length - 1));
- temp.addTemp(Double.parseDouble(split[0].substring(0, split[0].length() - 1)));
- for (int i = 1; i < split.length; i++) {
- temp.addTemp(Double.parseDouble(split[i].substring(0, split[i].length() - 1)));
- }
- this.dnevnaTemp.add(temp);
- }
- /*String s=scan.next();
- temp.setWhich(s.charAt(s.length()-1));
- temp.addTemp(Double.parseDouble(s.substring(0,s.length()-1)));
- while(scan.hasNext()){
- String m=scan.next();
- temp.addTemp(Double.parseDouble(m.substring(0,m.length()-1)));
- }
- this.dnevnaTemp.add(temp);
- scan.nextLine();
- }*/
- scan.close();
- }
- public void writeDailyStats(OutputStream outputStream, char scale){
- PrintWriter pw=new PrintWriter(outputStream);
- Collections.sort(dnevnaTemp);
- if(scale == 'F'){
- for(Temperature t:dnevnaTemp){
- if(t.getWhich() == 'F'){
- pw.print(t);
- }else{
- t.fromCelToFar();
- t.setWhich('F');
- pw.print(t);
- }
- }
- }else {
- for(Temperature t:dnevnaTemp){
- if(t.getWhich() == 'C'){
- pw.print(t);
- }else{
- t.fromFartoCel();
- t.setWhich('C');
- pw.print(t);
- }
- }
- }
- pw.flush();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement