Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.pichler.matura.celsius2fahrenheitconverter;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.ArrayList;
- import java.util.List;
- import javax.faces.bean.ManagedBean;
- import javax.faces.bean.SessionScoped;
- /**
- *
- * @author Patrick
- */
- @ManagedBean(name = "celsius2Fahrenheit")
- @SessionScoped
- public class Celsius2FahrenheitConverterBean {
- private double celsiusValue = 0;
- private double fahrenheitValue = 0;
- private SimpleDateFormat dateFormat;
- private List <HistoryItem> history = new ArrayList <>();
- public Celsius2FahrenheitConverterBean() {
- dateFormat = new SimpleDateFormat ("HH:mm dd.MM.YYYY");
- }
- public double getCelsiusValue() {
- return celsiusValue;
- }
- public void setCelsiusValue(double celsiusValue) {
- this.celsiusValue = celsiusValue;
- }
- public double getFahrenheitValue() {
- return fahrenheitValue;
- }
- public void setFahrenheitValue(double fahrenheitValue) {
- this.fahrenheitValue = fahrenheitValue;
- }
- public void convert() {
- fahrenheitValue = celsiusValue*1.8+32;
- history.add(new HistoryItem (new Date(), celsiusValue, fahrenheitValue));
- }
- public List<HistoryItem> getHistory() {
- return history;
- }
- public class HistoryItem {
- private Date date;
- private final double celsiusValue;
- private final double fahrenheitValue;
- public HistoryItem(Date date, double celsiusValue, double fahrenheitValue) {
- this.date = date;
- this.celsiusValue = celsiusValue;
- this.fahrenheitValue = fahrenheitValue;
- }
- public Date getDate() {
- return date;
- }
- public double getCelsiusValue() {
- return celsiusValue;
- }
- public double getFahrenheitValue() {
- return fahrenheitValue;
- }
- public String getDateFormatted () {
- return dateFormat.format(date);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment