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
Project 2
Project3
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);
}
}
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...
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 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 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 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 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 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 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 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 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 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...