⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weather.java

📁 SSD3 卡耐基梅隆大学教程 全部的参考答案啦`!不用账号下载哦`
💻 JAVA
字号:
import  java.io.*;

/**
 * Objects of this class store weather information for a city.
 * The following information is stored.
 * <ol>
 * <li>the city name, a <code>String</code>.</li>
 * <li>the lowest temperature observed, a <code>double</code>.</li>
 * <li>the highest temperature observed, a <code>double</code>.</li>
 * </ol>
 *
 * @author iCarnegie
 * @version  1.0.0
 */
public class Weather  {

	/** name of the city*/
	private String  city;

	/** lowest temperature*/
	private double  lowestTemp;

	/** highest temperature*/
	private double  highestTemp;
	
	/**
	 * Constructs a <code>Weather</code> object.
	 *
	 * @param initialCity  the name of the city.
	 * @param initialLowestTemp  the lowest temperature observed.
	 * @param initialHighestTemp  the highest temperature observed.
	 */
	public Weather (
		String initialCity,
		double initialLowestTemp,
		double initialHighestTemp) {

		this.city = initialCity;
		this.lowestTemp = initialLowestTemp;
		this.highestTemp = initialHighestTemp;
	}

	/**
	 * Obtains the name of the city.
	 *
	 * @return  the name of the city.
	 */
	public String  getCity()  {

		return  this.city;
	}

	/**
	 * Obtains the lowest temperature of the city.
	 *
	 * @return  the lowest temperature of city.
	 */
	public double  getLowestTemp()  {

		return  this.lowestTemp;
	}

	/**
	 * Obtains the highest temperature of the city.
	 *
	 * @return  the highest temperature of city.
	 */
	public double  getHighestTemp()  {

		return  this.highestTemp;
	}

	/**
	 * Returns a {@link String} with the weather info in a XML format
	 *
	 * @return  the newly created {@link String} with the weather info
	 */
	public String  getXML()  {

		/* Line separator */
		String NEW_LINE = System.getProperty("line.separator");

		return  "<city>"
			+ NEW_LINE
			+ "    <name> "+ getCity() + " </name>"
			+ NEW_LINE
			+ "    <lowest_temperature> " + getLowestTemp() 
			+ " </lowest_temperature>"
			+ NEW_LINE
			+ "    <highest_temperature> " + getHighestTemp() 
			+ " </highest_temperature>"
			+ NEW_LINE
			+ "</city>"
			+ NEW_LINE;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -