Question

Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much.

Create an Edit Menu in your GUI

Add a second menu to the GUI called Edit which will have one menu item called Search. Clicking on search should prompt the user using a JOptionPane input dialog to enter a car make. The GUI should then display only cars of that make. You will need to write a second menu handler called EditMenuHandler.

Project1

Sorting an Array of Cars/ Displaying in a GUI/Creating a Class Create a class called Car to represent a car. It should have f

Project 2

List of Cars Create a class called CarNode which has fields for the data (a Car) and next (CarNode) instance variables. Inclu

Project3

Create a File Menu in your GUI Add a file menu to your CarGUI with options to open a file for reading, and one to Quit the pr

Sorting an Array of Cars/ Displaying in a GUI/Creating a Class Create a class called Car to represent a car. It should have four private instance variables: A String for the make, a String for the model, an int for the year and an int for the mileage. The class should include a four-argument constructor and get and set methods for each instance variable. Override the method toString which should return the Car information in the same format as the input file (See below) Read the information about a car from a file that will be given to you on Blackboard, parse out the four pieces of information for the Car using a StringTokenizer, instantiate the Car and store the Car object in two different arrays (one of these arrays will be sorted in a later step). Once the file has been read and the arrays have been filled, sort one of the arrays by Make using Selection Sort. Display the contents of the arrays in a GUI that has a GridLayout with one row and two columns. The left column should display the cars in the order read from the file, and the right column should display the cars in sorted order The input file Each line of the input file will contain information about a car, with each piece of information separated by a comma. An example of the input file would be Toyota, Camry,2017, 41001 Subaru, Forester,2008,38913 If the line of the file does not have exactly four tokens, do not put it in the arrays; print it to the console Submitting the Project. You should have three files to submit for this project: Projectl.java CarGUI.java Car.java
List of Cars Create a class called CarNode which has fields for the data (a Car) and next (CarNode) instance variables. Include a one-argument constructor which takes a Car as a parameter. (For hints, see the PowerPoint on "Static vs. Dynamic Structures".) public CarNode (Car c) t. . h The instance variables should have protected access. There will not be any get and set methods for the two instance variables Create an abstract linked list class called CarList. This should be a linked list with head node as described in lecture. Modify it so that the data type in the nodes is Car. The no-argument constructor should create an empty list with first and last pointing to an empty head node, and length equal to zero Include an append method in this class Create two more linked list classes that extend the abstract class CarList One called UnsortedCarList and one called SortedCarList, each with appropriate no-argument constructors. Each of these classes should have a method called add(Car) that will add a new node to the list. In the case of the UnsortedCarList it will add it to the end of the list by calling the append method in the super class. In the case of the SortedCarList it will insert the node in the proper position to keep the list sorted Instantiate two linked lists, and for every car read from the file, add it to the unsorted and sorted lists using the add method. You will end up with the first list having the cars from the input file in the order they were read, and in the second list the cars will be in sorted order. Display the unsorted and sorted cars in the GUI just as in project 1 Submitting the Project. You should now have the following files to submit for this project: Project2.java Car.java CarGUI.java CarNode.java CarList.java UnsortedCarList.java SortedCarList.java
Create a File Menu in your GUI Add a file menu to your CarGUI with options to open a file for reading, and one to Quit the program. You will need a FileMenuHandler class to handle the events from the FileMenu. Create a jar file called Project3.jar and submit that to Blackboard by the due date for full credit.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

As per HOMEWORKLIB RULES if students ask multiple programming questions then solve the first one.I have solved the first program.
Please let me know if you have any doubts or you want me to modify the answer. And if you find this answer useful then don't forget to rate my answer as thumps up. Thank you! :)

import java.util.ArrayList;
import java.util.Arrays;
import java.io.FileReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.FileNotFoundException;
import java.lang.NumberFormatException;

public class Project1 {

    public static void main(String[] args) {

        Car[] carsArray = fillArray("/Users/swapnil/IdeaProjects/CarProject1/src/input.txt");
        Car[] unsortedCarsArray = Arrays.copyOf(carsArray, carsArray.length);

        sortCarsArray(carsArray);

        CarGUI carGui = new CarGUI("Cars");
        carGui.displayTwoArrayOfObjects(unsortedCarsArray, carsArray);
    }


    private static void sortCarsArray(Car[] carsArray) {
        if (carsArray.length == 0) {
            return;
        }
        for (int i = 0; i < carsArray.length - 1; i++) {
            int smallestAt = i;
            for (int j = i + 1; j < carsArray.length; j++) {
                if (carsArray[smallestAt].compareTo(carsArray[j]) > 0) {
                    smallestAt = j;
                }
            }
            Car temp = carsArray[i];
            carsArray[i] = carsArray[smallestAt];
            carsArray[smallestAt] = temp;
        }
    }


    private static Car[] fillArray(String myFile) {
        FileReader readfile = null;
        Scanner scannedFile = null;
        try {
            readfile = new FileReader(myFile);
            scannedFile = new Scanner(readfile);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }

        ArrayList<Car> carsArray = new ArrayList<>();
        String line = null;
        while (scannedFile.hasNextLine()) {
            line = scannedFile.nextLine();
            StringTokenizer tokenizer = new StringTokenizer(line, ",");

            ArrayList<String> carInfo = new ArrayList<>();

            while (tokenizer.hasMoreTokens()) {
                String token = tokenizer.nextToken();
                carInfo.add(token);
            }

            if (carInfo.size() == 4) {
                String make = carInfo.get(0);
                String model = carInfo.get(1);
                int year = toNumber(carInfo.get(2));
                int mileage = toNumber(carInfo.get(3));
                Car car = new Car(make, model, year, mileage);
                carsArray.add(car);
            } else {
                if (carInfo.size() <= 3) {
                    System.out.println(line + ": not enough tokens");
                } else {
                    System.out.println(line + ": more than 4 tokens");
                }
            }
        }

        scannedFile.close();
        Car[] cars = new Car[carsArray.size()];
        return carsArray.toArray(cars);
    }


    public static int toNumber(String inputNumString) {
        try {
            return Integer.parseInt(inputNumString);
        } catch (NumberFormatException e) {
            return 0;
        }
    }
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;

class CarGUI extends JFrame {
    private JScrollPane scrollPaneEast;
    private JScrollPane scrollPaneWest;
    private JTextArea sortedArrayTextArea;
    private JTextArea unsorteArrayTextArea;

    public CarGUI() {
        this("No title");
    }

    public CarGUI(String title) {
        super(title);

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(100, 100); // width, height
        this.setLocation(200, 200); // x, y of the window

        this.setLayout(new GridLayout(1, 2));

        this.unsorteArrayTextArea = new JTextArea("Unsorted Cars:\n");
        this.sortedArrayTextArea = new JTextArea("Sorted Cars:\n");

        this.scrollPaneEast = new JScrollPane(this.unsorteArrayTextArea);
        this.scrollPaneWest = new JScrollPane(this.sortedArrayTextArea);

        this.getContentPane().add(this.scrollPaneEast, BorderLayout.EAST);
        this.getContentPane().add(this.scrollPaneWest, BorderLayout.WEST);
    }

    public void displayTwoArrayOfObjects(Car[] unsortedArray, Car[] sortedArray) {
        showGui();

        String unsortedString = getCarsArrayString(unsortedArray);
        String sortedString = getCarsArrayString(sortedArray);

        this.unsorteArrayTextArea.append(unsortedString);
        this.sortedArrayTextArea.append(sortedString);
    }


    public void showGui() {
        this.pack();
        this.setVisible(true);
    }

    private String getCarsArrayString(Car[] cars) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < cars.length; i++) {
            sb.append(cars[i].toString() + "\n");
        }
        return sb.toString();
    }
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public class Car {

    private String make;
    private String model;
    private int year;
    private int mileage;

    public Car(String make, String model, int year, int mileage) {
        this.make = make;
        this.model = model;
        this.year = year;
        this.mileage = mileage;
    }

    public String getMake() {
        return make;
    }

    public String getModel() {
        return model;
    }

    public int getYear() {
        return year;
    }

    public int getMileage() {
        return mileage;
    }

    public void setMake(String make) {
        this.make = make;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public void setMileage(int mileage) {
        this.mileage = mileage;
    }

    @Override
    public String toString() {
        String carInfo = make + "," + model + "," + year + "," + mileage;
        return carInfo;
    }

    public int compareTo(Car car) {
        return make.compareTo(car.make);
    }
}

Add a comment
Know the answer?
Add Answer to:
Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one me...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • List of Candles Create a class called CandleNode which has fields for the data (a Candle)...

    List of Candles Create a class called CandleNode which has fields for the data (a Candle) and next (CandleNode) instance variables. Include a one-argument constructor which takes a Candle as a parameter. (For hints, see the PowerPoint on "Static vs. Dynamic Structures”.) public CandleNode (Candle c) { . . } The instance variables should have protected access. There will not be any get and set methods for the two instance variables. Create an abstract linked list class called CandleList. This...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J...

    *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J IN CLASS (IF IT DOESNT MATTER PLEASE COMMENT TELLING WHICH PROGRAM YOU USED TO WRITE THE CODE, PREFERRED IS BLUE J!!)*** ArrayList of Objects and Input File Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info...

  • Use BlueJ to write a program that reads a sequence of data for several car objects...

    Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info for any number of cars. (You should not assume that it will always be seven lines in the input file). Use notepad to create input file "inData.txt". File should be stored in the same folder where all files from BlueJ for this program...

  • For this assignment you will be creating a multi-file project in which you implement your own...

    For this assignment you will be creating a multi-file project in which you implement your own templated linked list and use it to create a simple list of composers. When doing this assignment, take small, incremental steps; trying to complete the lab in one go will make the lab more difficult. This means that any time you finish part of the lab, such as a linked list method, you should immediately test and debug it if necessary. Part 1: Creating...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • please help!!!! JAVA I done the project expect one part but I still give you all...

    please help!!!! JAVA I done the project expect one part but I still give you all the detail that you needed... and I will post my code please help me fix the CreateGrid() part in main and make GUI works    List Type Data Structures Overview : You will be implementing my version of a linked list. This is a linked list which has possible sublists descending from each node. These sublists are used to group together all nodes which...

  • Project overview: Create a java graphics program that displays an order menu and bill from a...

    Project overview: Create a java graphics program that displays an order menu and bill from a Sandwich shop, or any other establishment you prefer. In this program the design is left up to the programmer however good object oriented design is required. Below are two images that should be used to assist in development of your program. Items are selected on the Order Calculator and the Message window that displays the Subtotal, Tax and Total is displayed when the Calculate...

  • Project Description: In this project, you will combine the work you’ve done in previous assignments to...

    Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...

  • ***JAVA: Please make "Thing" movies. Objective In this assignment, you are asked to implement a bag...

    ***JAVA: Please make "Thing" movies. Objective In this assignment, you are asked to implement a bag collection using a linked list and, in order to focus on the linked list implementation details, we will implement the collection to store only one type of object of your choice (i.e., not generic). You can use the object you created for program #2 IMPORTANT: You may not use the LinkedList class from the java library. Instead, you must implement your own linked list...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT