code about the introduction of java 1

http://deanzacollegecis.jenniferparrish.net/home/c…link for activity13.1 & 13,2

http://deanzacollegecis.jenniferparrish.net/home/c…link for activity14.1 & 14.2

http://deanzacollegecis.jenniferparrish.net/home/c…link for lab7


Answer the following review questions from Lesson 13 by either typing directly into the textbox below or by uploading a document with your answers. Please include the question along with your answer to make your responses easy to read.

1. Identify and correct the mistakes in the below program:

public abstract class Dog {

private String name;

private int age;

public Dog() {

name = “No name yet”;

age = 0;

}

public Dog(String name, int age) {

this.name = name;

this.age = age;

}

public String getName() {

return name;

}

public int getAge() {

return age;

}

public abstract void printGreeting();

public void setAge(int age) {

this.age = age;

}

public void setName(String name ) {

this.name = name;

}

@Override public String toString() {

return “Name: ” + name + “nAge: ” + age;

}

}

public class Terrier extends Dog {

private boolean isKidFriendly;

public Terrier(String name, int age, boolean isKidFriendly) {

this.name = name;

this.age = age;

this.isKidFriendly = isKidFriendly;

}

public boolean getIsKidFriendly() {

return isKidFriendly;

}

public void setIsKidFriendly(boolean isKidFriendly) {

this.isKidFriendly = isKidFriendly;

}

@Override public String toString() {

return “Name” + name

+ “nAge: ” + age

+ “nKid-Friendly: ” + isKidFriendly;

}

}

2. Define polymorphism.

3. What will the following display to the console (don’t run the code until you work it out by hand!)

public class Person {

String name;

public Person(String name) {

this.name = name;

}

public void printGreeting() {

System.out.println(“Hi, my name is, ” + name + “!”);

}

}

public class Student extends Person {

double gpa;

public Student(String name, double gpa) {

super(name);

this.gpa = gpa;

}

public void printGreeting() {

super.printGreeting();

System.out.println(“My GPA of ” + gpa + ” is higher than yours!”);

}

}

public class Test {

public static void main(String[] args) {

Person yan = new Person(“Yan”);

Person leann = new Student(“Leann”, 4.0);

Student anh = new Student(“Anh”, 3.95);

yan.printGreeting();

leann.printGreeting();

anh.printGreeting();

}

}

Answer the following review questions from Lesson 14 by either typing directly into the textbox below or by uploading a document with your answers. Please include the question along with your answer to make your responses easy to read.

1. What is the difference between an interface and an abstract class?

    • What advantage does an interface offer over an abstract class?

2. Write an interface as follows:

    • The interface is named ServiceReminder
    • It has one method named timeForService that has no parameters and returns a boolean variable.

3. Now, update the below class so that is inherits from ServiceReminder

    • Note that the next service date should be 90 days from the last service

public abstract class Car {

private double gasGauge;

private double currMileage;

private String color;

private String make;

private String model;

private int daysLastService;

public Car(String color, String make, String model, int daysLastService) {

this.color = color;

this.make = make;

this.model = model;

gasGauge = 0.0;

currMileage = 0.0;

this.daysLastService = daysLastService;

}

@Override public String toString() {

return “Make: ” + make

+ “nModel: ” + model

+ “nColor: ” + color

+ “nGas Gauge: ” + gasGauge;

+ “nCurrent Mileage on this Tank: ” + currMileage

+ “nDays Since Last Service: ” + daysLastService;

}

}

4. Given the below Tesla class, update the class to inherit from the Comparable interface and also write a compareTo method that orders two Tesla objects according to 1. model, 2. range, and 3. color:

public class Tesla {

private String model;

private int range;

private String color;

public Tesla(String model, int range, String color) {

this.model = model;

this.range = range;

this.color = color;

}

@Override public boolean equals(Object o) {

if (this == o) {

return true;

} else if (!(o instanceof Tesla)) {

return false;

} else {

Tesla t = (Tesla) o;

return model.equals(t.model) &&

range == t.range &&

color.equals(t.color);

}

}

}

Need activity 13.1 &13.2 & question about lesson 13 today with 8 hours.

“Get 15% discount on your first 3 orders with us”
Use the following coupon
FIRST15

Order Now