Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Just Some Java Practice! The birds in the table below have different abilities r

ID: 3745569 • Letter: J

Question

Just Some Java Practice!

The birds in the table below have different abilities running, swimming, and flying. Each bird has a fixed set of abilities as listed in the table Type Running Swimming Flying Key Letter Penguin Ostrich Duck Sooty Tern Loon Hummingbird Assume the following Ability's are measured in speed (mph) for running/swimming and altitude (feet) for flying Specifications 1. Create a Java class called UsernameAssignment3 (please use this exact name) 2. Follow "CS1450 Programming Assignments Policy" 3. Design an ABSTRACT class called Bird containing the following fields and methods a. Private Data Fields name - String for bird's name ii, i. type-String for bird's specific type (ie. penguin, ostrich, etc.) b. Public Methods i. Getter and setter for each data field ii. ABSTRACT method interestingFact() -returns string representing fact about bird 4. Design 3 INTERFACES to represent the 3 abilities a. b. c. Swimmer with a method named swim() - returns swimming speed Runner with a method named run() - returns running speed Flyer with a method named fly() - returns flying altitude 5. Define 6 subclasses Penguin, Ostrich, Duck, Sooty Tern, Loon, and Humming Bird a. Each subclass must extend Bird. b. Each subclass must implement ONLY the interfaces for the abilities the bird possesses. i. For example: Humming Bird class only implements Flyer. Bird's name and ability values are in the file For the interesting facts, use the following strings c. d.

Explanation / Answer

import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; public class UsernameAssignment3 { public static void main(String args[]) throws IOException { ArrayList findCannotFly=new ArrayList(); ArrayList findCannotRun=new ArrayList(); ArrayList findCannotSwim=new ArrayList(); BufferedReader br = new BufferedReader(new FileReader("C:\CheggLeaning\src\file.txt")); try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { String[] animal = line.split(" "); if("p".equalsIgnoreCase(animal[0])) { Penguin p = new Penguin("penguin",Integer.parseInt(animal[2]),Integer.parseInt(animal[3]),Integer.parseInt(animal[4])); findCannotFly.add(p); } if("o".equalsIgnoreCase(animal[0])) { Ostrich p = new Ostrich("Ostrich",Integer.parseInt(animal[2]),Integer.parseInt(animal[3]),Integer.parseInt(animal[4])); findCannotFly.add(p); findCannotSwim.add(p); } if("d".equalsIgnoreCase(animal[0])) { Duck p = new Duck("Duck",Integer.parseInt(animal[2]),Integer.parseInt(animal[3]),Integer.parseInt(animal[4])); findCannotRun.add(p); } if("s".equalsIgnoreCase(animal[0])) { SootyTern p = new SootyTern("SootyTern",Integer.parseInt(animal[2]),Integer.parseInt(animal[3]),Integer.parseInt(animal[4])); findCannotRun.add(p); } if("h".equalsIgnoreCase(animal[0])) { HummingBird p = new HummingBird("HummingBird",Integer.parseInt(animal[2]),Integer.parseInt(animal[3]),Integer.parseInt(animal[4])); findCannotRun.add(p); findCannotSwim.add(p); } } } catch (IOException e) { e.printStackTrace(); } finally { br.close(); } } } /** * Created by kumar.biplav on 9/11/2018. */ public abstract class Bird { private String name; private String type; protected Bird(String name, int run,int swin,int fly) { this.name = name; this.type = type; } public String getName() { return name; } public String getType() { return type; } public void setType(String type) { this.type = type; } public void setName(String name) { this.name = name; } public abstract String interestingFact(); } /** * Created by kumar.biplav on 9/11/2018. */ public class Duck extends Bird implements Swimmer { protected Duck(String name,int run ,int swim,int fly) { super(name, run,swim,fly); } @Override public String interestingFact() { return "A duck's highest documented flight was over Nevada where a plane struck a mallard at 21,000 feet!"; } @Override public int swim() { return 0; } } /** * Created by kumar.biplav on 9/11/2018. */ public class HummingBird extends Bird implements Flyer { protected HummingBird(String name, int run ,int swim,int fly) { super(name, run,swim,fly); } @Override public String interestingFact() { return "My feet are so small and my flying so adept! I've got the fastest beating heart in the animal kingdom with heart rates exceeding 1,200 beats per minute."; } @Override public int fly() { return 0; } } /** * Created by kumar.biplav on 9/11/2018. */ public class Loon extends Bird implements Swimmer { protected Loon(String name, String type) { super(name, type); } @Override public String interestingFact() { return "My legs are so far back on my body that i cannot walkon land,instead i push myself along the ground on my chest."; } @Override public int swim() { return 0; } } /** * Created by kumar.biplav on 9/11/2018. */ public class Ostrich extends Bird implements Runner { protected Ostrich(String name, int run ,int swim,int fly) { super(name, run,swim,fly); } @Override public String interestingFact() { return "Who needs flying when you're the biggest bird on the earth I can grow upto 9 feet tall and weigh as much as 300 pounds!Don't mess with me!"; } @Override public int run() { return 0; } } /** * Created by kumar.biplav on 9/11/2018. */ public class Penguin extends Bird implements Swimmer{ protected Penguin(String name, int run ,int swim,int fly) { super(name, run,swim,fly); } @Override public String interestingFact() { String intrestingFact="I can't fly but I'm the fastest swimmer and deepeest diver of any bird and can stay under waterup to 20 minutes"; return intrestingFact; } @Override public int swim() { return 0; } } /** * Created by kumar.biplav on 9/11/2018. */ public interface Flyer { public int fly(); } /** * Created by kumar.biplav on 9/11/2018. */ public interface Runner { public int run(); } /** * Created by kumar.biplav on 9/11/2018. */ public interface Swimmer { public int swim(); } /** * Created by kumar.biplav on 9/11/2018. */ public class SootyTern extends Bird implements Flyer { protected SootyTern(String name, int run ,int swim,int fly) { super(name, run,swim,fly); } @Override public String interestingFact() { return "strange as it may sound I spend most of my life at seaand yet I cant't swim! I also take 1 to 2 second naps while flying"; } @Override public int fly() { return 0; } }