代码拉取完成,页面将自动刷新
//****************************************************************************************
//DVDCollection.java Author:WZW
//
//Represents a collection of DVD movies.
//****************************************************************************************
import java.text.NumberFormat;
public class DVDCollection {
private DVD[] collection;
private int count;
private double totalCost;
//-------------------------------------------------------------------------------------
//Constructor: Creates an initially empty collection.
//-------------------------------------------------------------------------------------
public DVDCollection() {
collection = new DVD[100];
count = 0;
totalCost = 0.0;
}
//-------------------------------------------------------------------------------------
//Adds a DVD to the collection, increasing the size of the
//collection array if necessary.
//------------------------------------------------------------------------------------
public void addDVD(String title, String director, int year, double cost, boolean bluray) {
if (count == collection.length)
increasingSize();
collection[count] = new DVD(title, director, year, cost, bluray);
totalCost += cost;
count++;
}
//---------------------------------------------------------------------------------------
//Returns a report describing the DVD collection.
//---------------------------------------------------------------------------------------
public String toString() {
NumberFormat fmt = NumberFormat.getCurrencyInstance();
String report = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
report += "My DVD Collection\n\n";
report += "Number of DVDs: " + count + "\n";
report += "Total cost: " + fmt.format(totalCost) + "\n";
report += "Average cost: " + fmt.format(totalCost / count);
report += "\n\n DVD List:\n\n";
for (int dvd = 0; dvd < count; dvd++)
report += collection[dvd].toString() + "\n";
return report;
}
//---------------------------------------------------------------------------------------
//Increases the capacity of the collection by creating a
//larger array and copying the existing collection into it.
//---------------------------------------------------------------------------------------
private void increasingSize()
{
DVD[] temp=new DVD[collection.length*2];
for(int dvd=0;dvd<collection.length;dvd++)
temp[dvd]=collection[dvd];
collection=temp;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。