62,612
社区成员
发帖
与我相关
我的任务
分享
package javaPractice;
import java.util.*;
public class TestBook {
public static void main(String[] argsment) {
Book[] book = new Book[10];
int j=0,k=0;
double[] arr = new double[5];
String[] name1 = {"Python","C","Linux/Unix","how to form Linux/Unix","Linux Shell"};
String[] name2 = {"ISBN 962-215-001-2","ISBN 962-215-001-3","ISBN 962-215-001-4","ISBN 962-215-001-5","ISBN 962-215-001-6","ISBN 962-215-001-8","ISBN 962-215-002-21"};
Random random = new Random();
for(int i=0;i<book.length;i++) {
j = random.nextInt(name1.length);
k = random.nextInt(name2.length);
book[i].setAuthor(name1[j]);
book[i].setISBN(name2[k]);;
book[i].setPrice((double)(Math.random()*200));
arr[i] = book[i].getPrice();
}
Arrays.sort(arr);
for(int i=0;i<book.length/2;i++) {
System.out.print("author:"+book[i].getAuthor());
System.out.print("\nISBN:"+book[i].getISBN());
System.out.println("\nprice:"+book[i].getPrice());
}
}
}
class Book{
private String author;
private String ISBN;//书号
private double price;
public String getAuthor() {return this.author;}
public void setAuthor(String author) {this.author = author;}
public String getISBN() {return this.ISBN;}
public void setISBN(String ISBN) {this.ISBN = ISBN;}
public double getPrice() {return this.price;}
public void setPrice(double price) {this.price = price;}
}
import java.util.*;
public class TestBook {
public static void main(String[] argsment) {
Book[] book = new Book[10];
int j = 0, k = 0;
double[] arr = new double[5];
String[] name1 = { "Python", "C", "Linux/Unix", "how to form Linux/Unix", "Linux Shell" };
String[] name2 = { "ISBN 962-215-001-2", "ISBN 962-215-001-3", "ISBN 962-215-001-4", "ISBN 962-215-001-5",
"ISBN 962-215-001-6", "ISBN 962-215-001-8", "ISBN 962-215-002-21" };
Random random = new Random();
for (int i = 0; i < book.length; i++) {
j = random.nextInt(name1.length);
k = random.nextInt(name2.length);
if (book[i] == null) {
book[i] = new Book();
}
book[i].setAuthor(name1[j]);
book[i].setISBN(name2[k]);
;
book[i].setPrice((double) (Math.random() * 200));
if (i < arr.length) {
arr[i] = book[i].getPrice();
}
}
Arrays.sort(arr);
for (int i = 0; i < book.length / 2; i++) {
System.out.print("author:" + book[i].getAuthor());
System.out.print("\nISBN:" + book[i].getISBN());
System.out.println("\nprice:" + book[i].getPrice());
}
}
}
class Book {
private String author;
private String ISBN;// 书号
private double price;
public String getAuthor() {
return this.author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getISBN() {
return this.ISBN;
}
public void setISBN(String ISBN) {
this.ISBN = ISBN;
}
public double getPrice() {
return this.price;
}
public void setPrice(double price) {
this.price = price;
}
}
package javaPractice;
import java.text.*;
import java.util.*;
public class TestBook {
public static void main(String[] argsment) {
Book[] book = new Book[10];
int j=0,k=0;
String[] name1 = {"杨红云","吴军","屈婉玲","李开复","凡尔纳","王小波"};
String[] name2 = {"ISBN 962-215-001-2","ISBN 962-215-001-3","ISBN 962-215-001-4","ISBN 962-215-001-5","ISBN 962-215-001-6","ISBN 962-215-001-8","ISBN 962-215-002-21"};
Random random = new Random();
DecimalFormat df = new DecimalFormat( "0.00");
double[] arr = new double[10];
for(int i=0;i<book.length;i++) {
book[i] = new Book();
}
for(int i=0;i<book.length;i++) {
j = random.nextInt(name1.length);
k = random.nextInt(name2.length);
book[i].setAuthor(name1[j]);
book[i].setISBN(name2[k]);;
book[i].setPrice(random.nextDouble()*200);
arr[i] = book[i].getPrice();
}
for(int i=0;i<book.length;i++) {
System.out.print("author:"+book[i].getAuthor());
System.out.print(" "+book[i].getISBN());
System.out.println(" price:"+df.format(book[i].getPrice()));
}
Arrays.sort(arr);
for(int i=0;i<book.length;i++) {
if(book[i].getPrice() == arr[arr.length-1]) {
System.out.println("书价最高图书的书号为"+book[i].getISBN());
}
}
}
}
class Book{
private String author;
private String ISBN;//书号
private double price;
public String getAuthor() {return this.author;}
public void setAuthor(String author) {this.author = author;}
public String getISBN() {return this.ISBN;}
public void setISBN(String ISBN) {this.ISBN = ISBN;}
public double getPrice() {return this.price;}
public void setPrice(double price) {this.price = price;}
}
public static void main(String[] argsment)
{
Book[] book = new Book[10];
for (int i = 0; i < 10; i++)
{
book[i] = new Book();
}
int j = 0, k = 0;
double[] arr = new double[10];
String[] name1 = {"Python", "C", "Linux/Unix", "how to form Linux/Unix", "Linux Shell"};
String[] name2 = {"ISBN 962-215-001-2", "ISBN 962-215-001-3", "ISBN 962-215-001-4", "ISBN 962-215-001-5", "ISBN 962-215-001-6", "ISBN 962-215-001-8", "ISBN 962-215-002-21"};
Random random = new Random();
for (int i = 0; i < book.length; i++)
{
j = random.nextInt(name1.length);
k = random.nextInt(name2.length);
book[i].setAuthor(name1[j]);
book[i].setISBN(name2[k]);
book[i].setPrice((double)(Math.random() * 200));
arr[i] = book[i].getPrice();
}
Arrays.sort(arr);
for (int i = 0; i < book.length / 2; i++)
{
System.out.print("author:" + book[i].getAuthor());
System.out.print("\nISBN:" + book[i].getISBN());
System.out.println("\nprice:" + book[i].getPrice());
}
}