PJF16

Untitled

May 30th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package com.pichler.matura.celsius2fahrenheitconverter;
  8.  
  9. import java.text.SimpleDateFormat;
  10. import java.util.Date;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13. import javax.faces.bean.ManagedBean;
  14. import javax.faces.bean.SessionScoped;
  15.  
  16. /**
  17.  *
  18.  * @author Patrick
  19.  */
  20. @ManagedBean(name = "celsius2Fahrenheit")
  21. @SessionScoped
  22. public class Celsius2FahrenheitConverterBean {
  23.  
  24.     private double celsiusValue = 0;
  25.     private double fahrenheitValue = 0;
  26.     private SimpleDateFormat dateFormat;
  27.     private List <HistoryItem> history = new ArrayList <>();
  28.    
  29.    
  30.     public Celsius2FahrenheitConverterBean() {
  31.         dateFormat = new SimpleDateFormat ("HH:mm dd.MM.YYYY");
  32.     }
  33.  
  34.     public double getCelsiusValue() {
  35.         return celsiusValue;
  36.     }
  37.  
  38.     public void setCelsiusValue(double celsiusValue) {
  39.         this.celsiusValue = celsiusValue;
  40.     }
  41.  
  42.     public double getFahrenheitValue() {
  43.         return fahrenheitValue;
  44.     }
  45.  
  46.     public void setFahrenheitValue(double fahrenheitValue) {
  47.         this.fahrenheitValue = fahrenheitValue;
  48.     }
  49.  
  50.     public void convert() {
  51.         fahrenheitValue = celsiusValue*1.8+32;
  52.         history.add(new HistoryItem (new Date(), celsiusValue, fahrenheitValue));
  53.     }
  54.  
  55.     public List<HistoryItem> getHistory() {
  56.         return history;
  57.     }
  58.    
  59.   public class HistoryItem {
  60.         private Date date;
  61.         private final double celsiusValue;
  62.         private final double fahrenheitValue;
  63.  
  64.         public HistoryItem(Date date, double celsiusValue, double fahrenheitValue) {
  65.             this.date = date;
  66.             this.celsiusValue = celsiusValue;
  67.             this.fahrenheitValue = fahrenheitValue;
  68.         }
  69.  
  70.         public Date getDate() {
  71.             return date;
  72.         }
  73.  
  74.         public double getCelsiusValue() {
  75.             return celsiusValue;
  76.         }
  77.  
  78.         public double getFahrenheitValue() {
  79.             return fahrenheitValue;
  80.         }
  81.        
  82.         public String getDateFormatted () {
  83.             return dateFormat.format(date);
  84.         }
  85.        
  86.        
  87.     }
  88.    
  89. }
Advertisement
Add Comment
Please, Sign In to add comment