SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 305 Weeks Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 11 Dec 2017 My Price 10.00

case class Author(penName: String, realName: String)

I have one more question to ask. Thank you so much!

  • object Amazon {

      case class Author(penName: String, realName: String)
      case class Publisher(name: String)
      case class Book(title: String, author: List[Author], publisher: Publisher, year: Int, price: Double)
      case class Series(name: String, books: List[Book])

      // Find all books that written by an author
      // The authorName should match either pen or real name.
      // If there are no books that matches the author, return an empty list
      def findAll(books: List[Book], authorName: String): List[Book] = ???

      // Find all books that was published on a given year.
      // If no books were published that year, you should get an empty list
      def findAll(books: List[Book], year: Int): List[Book] = ???

      // Find average price of all the books by the author
      def findAveragePrice(books: List[Book], author: Author): Double = ???

      // Find average price of all the books given a publisher
      def findAveragePrice(books: List[Book], publisher: Publisher): Double = ???

      // Generalize above two functions into one that finds a average price among books that matches a predicate
      def findAverage(books: List[Book], p: Book => Boolean): Double = ???

      // Given a list of books, produce a list of unique authors
      // You should use .toSet method on List
      def authors(books: List[Book], author: Author): Set[Author] = ???

      // Given a list of books, produce a list of unique publisher
      // You should use .toSet method on List
      def publishers(books: List[Book], publisher: Publisher): Set[Publisher] = ???

      // Generalize above two functions.
      // You should use .toSet method on List
      def toSet[A](books: List[Book], p: A => Boolean): Set[A] = ???

      // Given a book series, find the total cost of the collection
      def total(series: Series): Double = ???

      // Given a book series, produce a list of unique authors that contributed
      // You should use .toSet method on List
      def authors(series: Series): Set[Author] = ???

      def main(args: Array[String]): Unit = {
        val huckfinn = Book(
          "The Adventures of Huckleberry Finn",
          List(Author("Mark Twain", "Samuel Langhorne Clemens")),
          Publisher("Chatto & Windus"), 1885, 5.40)

        val design = Book(
          "Design Patterns: Elements of Reusable Object-Oriented Software",
          List(
            Author("Erich Gamma", "Erich Gamma"),
            Author("Richard Helm", "Richard Helm"),
            Author("Ralph Johnson", "Ralph Johnson"),
            Author("John Vlissides", "John Vlissides")
          ), Publisher("Addison-Wesley"), 1994, 28.11)

        val lotr = Series("The Lord of the Rings", List(
          Book(
            "The Followship of the Ring",
            List(Author("J. R. R. Tolkien", "John Ronald Reuel Tolkien")),
            Publisher("George Allen & Unwin"), 1954, 7.99)
        ))

        val amazon = List(huckfinn, design)

        assert(findAll(amazon, "Richard Helm") == List(design))

        assert(total(lotr) == 7.99)

        //You should write more tests
      }

    }
    object Lab12 {

      //This is a immutable data structure.
      //All the methods should not modify the existing List
      trait List[+A] {
        //Returns the (i + 1)th element in the list
        def get(i: Int): A = ???

        //Prepends an element at the beginning of the list
        def prepend[B >: A](a: B): List[B] = Cons(a, this)

        //Appends an element at the end of the list
        def append[B >: A](b: B): List[B] = ???

        //Replaces the head of the list with a
        def setHead[B >: A](a: B): List[B] = ???

        //Removes the last element in the list
        def init: List[A] = ???

        //Removes the first n elements in the list
        def drop(n: Int): List[A] = ???

        //Removes last (length - n) elements in the list
        def take(n: Int): List[A] = ???

        //Appends two lists together
        def append[B >: A](that: List[B]): List[B] = ???

        //Produces B by combining all the elments in the list using the function f starting with z then right most element
        def foldRight[B](z: B)(f: (A, B) => B): B = ???

        //Produces B by combining all the elments in the list using the function f starting with z then left most element
        def foldLeft[B](z: B)(f: (B, A) => B): B = ???

        //returns true if all of the elements in the list returns true for the predicate f
        def forAll(f: A => Boolean): Boolean = ???

        //returns the length of the list
        def length: Int = ???

        //returns a reverse of the list (use foldLeft or foldRight)
        def reverse: List[A] = ???

        //Transform each of the element using f
        def map[B](f: A => B): List[B] = ???

        //Transform each of the element using f then flatten
        def flatMap[B](f: A => List[B]): List[B] = ???

        //returns a new list only containing elements that satisfies the predicate f
        def filter(f: A => Boolean): List[A] = ???
      }

      object List {
        //Given a list of list, return a flattened list
        // List(List(1,2), List(3,4), 5).flatten == List(1,2,3,4,5)
        def flatten[A](list: List[List[A]]): List[A] = ???

        //Creates a new list of size n filled with element a
        def fill[A](n: Int)(a: A): List[A] = ???

        def apply[A](args: A*): List[A] =
          if (args.isEmpty) Nil
          else Cons(args.head, apply(args.tail: _*))
      }

      case object Nil extends List[Nothing]

      case class Cons[A](head: A, tail: List[A]) extends List[A]

      def main(args: Array[String]): Unit = {
        assert(List(1,2,3,4).get(2) == 3)
        assert(List(1,2,3).prepend(0) == List(0,1,2,3))
        assert(List(1,2).append(3) == List(1,2,3))
        assert(List(1,2,3).setHead(0) == List(0,2,3))
        assert(List(1,2,3).init == List(1,2))
        assert(List(1,2,3,4,5).drop(2) == List(3,4,5))
        assert(List(1,2,3,4,5).take(2) == List(1,2))
        assert(List(1,2).append(List(3,4)) == List(1,2,3,4))
        assert(List(1,2,3,4,5).forAll(x => x > 0) == true)
        assert(List(1,2,3,4,5).forAll(x => x < 3) == false)
        assert(List(1,2,3,4).foldRight(0)((a, b) => a + b) == 10)
        assert(List(1,2,3,4).foldLeft(0)((b, a) => b + a) == 10)
        assert(List(1,2,3,4).length == 4)
        assert(List(1,2,3,4).reverse == List(4,3,2,1))
        assert(List.flatten(List(List(1,2), List(3,4))) == List(1,2,3,4))
        assert(List(1,2,3).map(x => x * x) == List(1, 4, 9))
        assert(List(1,2,3).flatMap(x => List(x, x)) == List(1,1,2,2,3,3))
        assert(List(1,2,3,4,5).filter(x => x % 2 == 0) == List(2,4))
        assert(List.fill(3)(1) == List(1,1,1))
      }
    }


Attachments:

Answers

(5)
Status NEW Posted 11 Dec 2017 11:12 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)