Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1 Create an Interface called Printable, that defines 3 methods: toString() and display() and printToFile() [10 points] Update your class from your previous assignments

Part 1

Create an Interface called Printable, that defines 3 methods: toString() and display() and printToFile() [10 points]

Update your class from your previous assignments to have the following

Implement the Comparable Interface [5 points]

Override to compareTo() method - (I'ts up to you to determine the best way to sort your objects) [20 points]

Implement the Printable interface - You will also need to implement all the methods, some of which you should already have. The printToFile() method should just simply print your data to a text file.[10 points]

In the driver class (the class with your main method), define your own generic static method called maxHighest()

It should have 3 generic parameters [10 points]

It will return the max highest item (based on their sorting order) of the 3 parameters [10 points]

In your main method, test the maxHighest() method by passing the following objects to it. It should print out the some text describing it as the 2nd highest item:

3 Strings [5 points]

3 Integers [5 points]

3 Objects of your Class from your previous assignments [5 points]

Previous assignment:

public class Coffee {

protected String color;

protected double size;

protected int price;

// default constructor

public Coffee() {

color = " ";

size = 0;

price = 0;

}

// parameterized constructor

public Coffee(String c, double s, int p) {

color = c;

size = s;

price = p;

}

public void setColor(String c) { // Can right click to generate get and set methods, under source

color = c;

}

public void setSize(double s) {

size = s;

}

public void setPrice(int p) {

price = p;

}

public String getColor() {

return color;

}

public double getSize() {

return size;

}

public int getPrice() {

return price;

}

public void display() {

System.out.println(color);

System.out.println(size + " inches");

System.out.println("$" + price);

//System.out.print(" ");

}

}

public class Starbucks extends Coffee {

private boolean isDecaf;

public Starbucks() {

super("", 0, 0);

this.isDecaf = false;

}

public Starbucks(boolean isDecaf, String color, double size, int memory) {

super(color, size, memory);

this.isDecaf = isDecaf;

}

public void setisDecaf(boolean isDecaf)

{

this.isDecaf = isDecaf;

}

public boolean getisDecaf() {

return isDecaf;

}

public void display() {

super.display();

System.out.println("and it is decaf: " + isDecaf);

}

}

import java.util.ArrayList;

public class Demo {

public static void main(String[] args) {

Coffee a = new Coffee();

Coffee b = new Coffee("Black", 6, 4);

Starbucks c = new Starbucks();

Starbucks d = new Starbucks(true, "Black", 6, 4);

a.setColor("Black");

a.setSize(6);

a.setPrice(4);

c.setColor("Black");

c.setSize(8);

c.setPrice(6);

c.setisDecaf(false);

ArrayList arr = new ArrayList();

arr.add(a);

arr.add(b);

arr.add(c);

arr.add(d);

displayAll(arr);

}

public static void displayAll(ArrayList Starbucks) {

for (int i=0; i

Starbucks.get(i).display();

}

}

}

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

Step: 3

blur-text-image

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

Demystifying Databases A Hands On Guide For Database Management

Authors: Shiva Sukula

1st Edition

8170005345, 978-8170005346

More Books

Students also viewed these Databases questions