发布网友 发布时间:2022-04-22 09:25
共1个回答
热心网友 时间:2023-10-05 06:02
//刚才修改了一下后面排序,你在看看第一次,忘记了!!
public class OrderDemo1
{
public static void main(String[] args)
{
System.out.println("\n\t\t==========升级需求!==========\n");
init();
}//初始化!
private static void init()
{
Order[] orr=new Order[5];
int n=1000,m=10;
//创建对象!
for (int i=0;i<5;i++)
{
orr[i]=new Order();
int number[]=new int[5],money[]=new int[5];
String[] srr=new String[5];
for (int j=0;j<5 ;j++ )
{
number[j]=n++;
money[j]=m++;
srr[j]=(char)(m+54)+"商品0"+j;
}
orr[i].set(number,money,srr);
}
//调用toString打印功能!
for (int i=0;i<orr.length;i++)
{
System.out.println("\t\t编号"+(i+1)+"订单细分如下:");
orr[i].toString();
System.out.println();
}
System.out.println("\t\t<-------------按照金额大小倒序打印---------------->\n");
//按照订单金额倒序!
for (int i=orr.length-1;i>=0;i--)
{
orr[i].tostring();
}
}
}
//订单!
class Order
{
private int[] number=new int[5];//订单号!
private int[] money=new int[5];//订单金额!
private String[] arr=new String[5];//商品数组!
void set(int[] number,int[] money,String[] arr)
{
this.number=number;
this.money=money;
this.arr=arr;
}
//重写toString
public String toString()
{
for (int i=0;i<arr.length ;i++ )
{
System.out.println("商品编号=>"+number[i]+"\t订单金额=>"+money[i]+"\t商品名称=>"+arr[i]);
}
return "";
}
public String tostring()
{
for (int i=arr.length-1;i>=0 ;i-- )
{
System.out.println("商品编号=>"+number[i]+"\t订单金额=>"+money[i]+"\t商品名称=>"+arr[i]);
}
return "";
}
}