Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ANSWER ALL PARTS IN JAVA Part 1 Part 2 Part 3 Answer all parts in Java We have written the following BankAccount interface: interface BankAccount

ANSWER ALL PARTS IN JAVA

Part 1

image text in transcribedPart 2

image text in transcribedimage text in transcribedPart 3

image text in transcribedimage text in transcribedAnswer all parts in Java

We have written the following BankAccount interface: interface BankAccount { public String getType(); We have also written the following two classes, both of which implement the Bank Account interface: class Savings Account implements BankAccount { public String getType() { return "Savings" ; class CheckingAccount implements Bank Account { public String getType() { return "Checking"; TASK: Create a Human class that has the following properties: It must have a public instance variable of type BankAccount called account It should have a constructor that has one String parameter. If the constructor's argument is "Savings", the account instance variable must be initialized to a new Savings Account object. If the constructor's argument is "Checking", the account instance variable must be initialized to a new Checking Account object. If the constructor's argument is anything else, the account instance variable must be initialized to null We have written the following FastFuriousMovies class below, and we want to be able to iterate over the movies using a for-each loop. However, our code doesn't work, and we have no idea why. TASK: Fix the bug(s) in our code. EXAMPLE: After running the following lines of code: Fast Furious Movies amazingMovies = new FastFuriousMovies(); for(String m: amazingMovies) { System.out.println(m); We will print the following: The Fast and the Furious 2 Fast 2 Furious The Fast and the Furious: Tokyo Drift Fast & Furious Fast Five Fast & Furious 6 Furious 7 The Fate of the Furious Fast & Furious Presents: Hobbs & Shaw 1 class Fast FuriousMovies { final private ArrayList movies; public FastFuriousMovies() { this.movies = new ArrayList(); this.movies.add("The Fast and the Furious"); this.movies.add("2 Fast 2 Furious"); this.movies.add("The Fast and the Furious: Tokyo Drift"); this.movies.add("Fast & Furious"); this.movies.add("Fast Five"); this.movies.add("Fast & Furious 6"); this.movies.add("Furious 7"); this.movies.add("The Fate of the Furious"); this.movies.add("Fast & Furious Presents: Hobbs & Shaw"); We have written the following Movie class below, and we want to be able to use the Collections. sort method to sort an ArrayList. We want to sort by the title instance variable, and we want to break ties by the year instance variable. However, our code doesn't work, and we have no idea why. TASK: Fix the bug(s) in our code. EXAMPLE: After running the following lines of code: ArrayList movies = new ArrayList(); movies.add(new Movie("Good Burger", 1997)); movies.add(new Movie("The Lord of the Rings: The Fellowship of the Ring", 2001)); movies.add(new Movie ("The Fast and the Furious", 2001)); movies.add(new Movie("The Fast and the Furious", 1954); // this is a real movie! Collections.sort(movies); for (Movie m : movies) { System.out.println(m); We will print the following: (Good Burger, 1997) (The Fast and the Furious, 1954) (The Fast and the Furious, 2001) (The Lord of the Rings: The Fellowship of the Ring, 2001) class Movie { // instance variables private final String title; private final int year; // constructor public Movie(String t, int y) { if(t == null) { this.title = ""; } else { this.title = t; this.year = y; // instance methods public String getTitle() { return this.title; public int getYear() { return this.year; public String toString() { return "(" + this.title + "," + this.year + ")"; public boolean equals(Object o) { return (o instanceof Movie) && 1/ check if ois a Movie this.year == ((Movie)o).year && // check years for equality this.title.equals(((Movie)o).title); // check titles for equality We have written the following BankAccount interface: interface BankAccount { public String getType(); We have also written the following two classes, both of which implement the Bank Account interface: class Savings Account implements BankAccount { public String getType() { return "Savings" ; class CheckingAccount implements Bank Account { public String getType() { return "Checking"; TASK: Create a Human class that has the following properties: It must have a public instance variable of type BankAccount called account It should have a constructor that has one String parameter. If the constructor's argument is "Savings", the account instance variable must be initialized to a new Savings Account object. If the constructor's argument is "Checking", the account instance variable must be initialized to a new Checking Account object. If the constructor's argument is anything else, the account instance variable must be initialized to null We have written the following FastFuriousMovies class below, and we want to be able to iterate over the movies using a for-each loop. However, our code doesn't work, and we have no idea why. TASK: Fix the bug(s) in our code. EXAMPLE: After running the following lines of code: Fast Furious Movies amazingMovies = new FastFuriousMovies(); for(String m: amazingMovies) { System.out.println(m); We will print the following: The Fast and the Furious 2 Fast 2 Furious The Fast and the Furious: Tokyo Drift Fast & Furious Fast Five Fast & Furious 6 Furious 7 The Fate of the Furious Fast & Furious Presents: Hobbs & Shaw 1 class Fast FuriousMovies { final private ArrayList movies; public FastFuriousMovies() { this.movies = new ArrayList(); this.movies.add("The Fast and the Furious"); this.movies.add("2 Fast 2 Furious"); this.movies.add("The Fast and the Furious: Tokyo Drift"); this.movies.add("Fast & Furious"); this.movies.add("Fast Five"); this.movies.add("Fast & Furious 6"); this.movies.add("Furious 7"); this.movies.add("The Fate of the Furious"); this.movies.add("Fast & Furious Presents: Hobbs & Shaw"); We have written the following Movie class below, and we want to be able to use the Collections. sort method to sort an ArrayList. We want to sort by the title instance variable, and we want to break ties by the year instance variable. However, our code doesn't work, and we have no idea why. TASK: Fix the bug(s) in our code. EXAMPLE: After running the following lines of code: ArrayList movies = new ArrayList(); movies.add(new Movie("Good Burger", 1997)); movies.add(new Movie("The Lord of the Rings: The Fellowship of the Ring", 2001)); movies.add(new Movie ("The Fast and the Furious", 2001)); movies.add(new Movie("The Fast and the Furious", 1954); // this is a real movie! Collections.sort(movies); for (Movie m : movies) { System.out.println(m); We will print the following: (Good Burger, 1997) (The Fast and the Furious, 1954) (The Fast and the Furious, 2001) (The Lord of the Rings: The Fellowship of the Ring, 2001) class Movie { // instance variables private final String title; private final int year; // constructor public Movie(String t, int y) { if(t == null) { this.title = ""; } else { this.title = t; this.year = y; // instance methods public String getTitle() { return this.title; public int getYear() { return this.year; public String toString() { return "(" + this.title + "," + this.year + ")"; public boolean equals(Object o) { return (o instanceof Movie) && 1/ check if ois a Movie this.year == ((Movie)o).year && // check years for equality this.title.equals(((Movie)o).title); // check titles for equality

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions