Looking to add an absract method to my current java program. I missed this requi
ID: 3807848 • Letter: L
Question
Looking to add an absract method to my current java program.
I missed this requirment when creating the program and now cannot seem to find a place for a absract methodwithout break the program
Any ideas?
Moives.java
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class Moives extends JFrame
{
private static Game movies[];
private static JButton sort = new JButton("Perform Sorting");
private static JTextArea textarea = new JTextArea(20, 35);
public Moives(){
sort.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Sorting.selectionSort(movies);
//Displaying result in textarea
display();
}
});
setLayout(new FlowLayout());
add(new JScrollPane(textarea));
add(sort);
}
public static void setFrame(final JFrame frame, final int width, final int height) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
frame.setTitle(frame.getClass().getSimpleName());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width, height);
frame.setVisible(true);
}
});
}
public static void display()
{
String ans="";
for(Game Game:movies)
ans+=Game+" ";
textarea.setText(ans);
}
public static void main(String[] args){
//Game[] movies=new Game[7];
movies=new Game[7];
movies[0]= new Game ("The Godfather", "Francis Ford Coppola", 1972, 24.95, true);
movies[1]= new Game ("District 9", "Neill Blokamp", 2009, 19.95, false);
movies[2]= new Game ("Iron Man", "Jon Favreau", 2008, 15.95, false);
movies[3]= new Game ("All About Eve", "Joseph Mankiewicz", 1950, 17.50, false);
movies[4]= new Game ("The Matrix", "Andy & Lana Wachowski", 1999, 19.95, true);
movies[5]= new Game ("Iron Man 2", "Jon Favreau", 2010, 22.99, false);
movies[6]= new Game ("Casablanca", "Michael Curtiz", 1942, 19.95, false);
setFrame(new Moives(), 500, 500);
display();
}
}
Game.java
import java.text.NumberFormat;
public class Game implements Comparable{
private String tile, company;
private int year;
private double rating;
private boolean virtualReality;
private String title;
public Game (String title, String company, int year, double rating, boolean virtualReality){
this.title=title;
this.year= year;
this.company=company;
this.rating=rating;
this.virtualReality=virtualReality;
}
public String getTitle(){
return title;
}
public String toString(){
NumberFormat fmt = NumberFormat.getCurrencyInstance();
String description;
description = fmt.format(rating) + " " + year + " ";
description += title + " " + company;
if (virtualReality)
description += " " + "Virtual Reality";
return description;
}
public int compareTo(Object otherObject){
Game otherGame=(Game)otherObject;
return getTitle().compareTo(otherGame.getTitle());
}
}
Sorting.java
public class Sorting {
public static void selectionSort(Comparable[] list){
int min;
Comparable temp;
for(int index=0; index min=index;
for (int scan = index+1; scan < list.length; scan++)
if (list[scan].compareTo(list[min])<0)
min=scan;
temp=list[min];
list[min]=list[index];
list[index]=temp;
}
}
}
Explanation / Answer
//try this
abstract class Sort {
abstract void sort(Comparable[] list);
}
class selectionsort extends Sort
{
@Override
void sort(Comparable[] list) {
// TODO Auto-generated method stub
//your selection sort code here
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.