Homework

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

1.

private static void statisticsList(){


List<Message> list = getMessageList();
//Calculate Total
Long sum= list.stream().mapToLong(Message::getId).sum();
System.out.println("sum = " + sum);

//MaximumNumber
Optional<Message> maxMassage =
list.stream().collect(Collectors.maxBy(Comparator.comparing(Message::getId)));
Long maxId = maxMassage.get().getId();
System.out.println("maxId = " + maxId);

LongSummaryStatistics lss =
list.stream().collect(Collectors.summarizingLong(Message::getId));
System.out.println("sum = " + lss.getSum());
System.out.println("max = " + lss.getMax());
System.out.println("min = " + lss.getMin());
System.out.println("avg = " + lss.getAverage());
}

2.

public class Student {

private String id;

private String fname;

private String lname;

private String address;

public Student() { }

public Student(String id, String fname, String lname, String address) {


this.id = id;
this.fname = fname;
this.lname = lname;
this.address = address;
}

public String getId() {


return id;
}
public void setId(String id) {
this.id = id;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}

public Class Checkinformation{

package bookTest2;

public class Stock {

String symbol ;

String name;

double previousPrice ;

double currentPrice ;

public Stock( String symbol , String name){


this.name = name;
this.symbol = symbol;
}
public double getPreviousPrice() {
return previousPrice;
}
public void setPreviousPrice(double previousPrice) {
this.previousPrice = previousPrice;
}
public double getCurrentPrice() {
return currentPrice;
}
public void setCurrentPrice(double currentPrice) {
this.currentPrice = currentPrice;
}

public double getChangePercent(){


double percent = (currentPrice-previousPrice)/previousPrice;
return percent*100;
}
}

package bookTest2;

public class testStock {


public static void main(String[] args) {

Stock stock = new Stock("600000","浦发银行");


stock.previousPrice = 25.5;

stock.currentPrice = 28.6;
System.out.println(stock.getChangePercent()+" %");
}

You might also like