I need two things in one project average grade without minimum and maximum and display of books from the list of which the date of publication is above a certain value
import java.awt.print.Book;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
public class sredniaocen {
class Book {
int pubyear;
String title;
public Book(String title, int pubyear) {
this.title = title;
this.pubyear = pubyear;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getPubyear() {
return pubyear;
}
public void setPubyear(int pubyear) {
this.pubyear = pubyear;
}
}
public static void main(String args[]) {
ArrayList<Double> list = new ArrayList<Double>();
list.add(3.0);
list.add(5.0);
list.add(3.0);
list.add(4.0);
list.add(4.0);
list.add(5.0);
double sum = 0;
for (double x : list) {
System.out.println("Wartość elementu: " + x);
sum += x;
}
double min = Collections.min(list);
double max = Collections.max(list);
System.out.println("Suma elementów: " + sum);
System.out.println("Min: " + min);
System.out.println("Max: " + max);
double average = (sum - min - max) / (list.size() - 2);
System.out.println(average);
Book book = new Book();
book.pubyear = 2000;
book.title = "abcd";
LinkedList<Book> booklist = new LinkedList<Book>();
booklist.add(book.pubyear, book.title);
// Retrieve and display an element at index 7
System.out.println("Książka = " + list.get(book));
}
}
:62:40
java: incompatible types: java.lang.String cannot be converted to sredniaocen.BookList
:66:52
java: incompatible types: sredniaocen.Book cannot be converted to int
=============================
working code complete
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
public class sredniaocen {
class Book {
int pubyear;
String title;
public Book(String title, int pubyear) {
this.title = title;
this.pubyear = pubyear;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getPubyear() {
return pubyear;
}
public void setPubyear(int pubyear) {
this.pubyear = pubyear;
}
class BookList {
}
}
public static void main(String args[]) {
ArrayList<Double> list = new ArrayList<Double>();
list.add(3.0);
list.add(5.0);
list.add(3.0);
list.add(4.0);
list.add(4.0);
list.add(5.0);
double sum = 0;
for (double x : list) {
System.out.println("Wartość elementu: " + x);
sum += x;
}
double min = Collections.min(list);
double max = Collections.max(list);
System.out.println("Suma elementów: " + sum);
System.out.println("Min: " + min);
System.out.println("Max: " + max);
double average = (sum - min - max) / (list.size() - 2);
System.out.println("Średnia bez najwyższej i najniższej oceny: " + average);
LinkedList<Book> booklist = new LinkedList<Book>();
booklist.add(new Book("abc", 1998));
booklist.add(new Book("def", 1999));
booklist.add(new Book("ghi", 2000));
booklist.add(new Book("jkl", 2001));
booklist.add(new Book("mno", 1978));
booklist.add(new Book("prs", 2012));
booklist.add(new Book("tuw", 2006));
for (Book book : booklist) {
if (book.getPubyear() > 2000) {
System.out.println(book.getTitle());
}
}
}