+1 (315) 557-6473 

Create a Program to Implement String Manipulation in Java Assignment Solution.


Instructions

Objective
To complete a Java assignment, you need to write a program that implements string manipulation in the Java language. This involves working with various string operations such as concatenation, substring extraction, and character manipulation. By carefully crafting your Java code, you can demonstrate a solid understanding of how to manipulate strings effectively. Pay attention to details, follow best practices, and test your program thoroughly to ensure it functions as expected.

Requirements and Specifications

program to implement string manipulation in java
program to implement string manipulation in java 1

Source Code

import java.io.BufferedReader;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

import javax.swing.*;

import javax.swing.filechooser.FileNameExtensionFilter;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class App extends JFrame {

public static void main(String[] args) throws Exception {

// list of polynomials

List polynomials = new ArrayList();

JFrame f = new JFrame();

JButton btn = new JButton("Open file...");

btn.setBounds(20,20,100,20);

JTextArea txt = new JTextArea();

txt.setBounds(20, 60, 300, 300);

f.add(txt);

btn.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

JFileChooser fileChooser = new JFileChooser();

fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files", "txt");

fileChooser.setFileFilter(filter);

int result = fileChooser.showOpenDialog(btn);

if (result != JFileChooser.CANCEL_OPTION) {

File fileName = fileChooser.getSelectedFile();

if ((fileName == null) || (fileName.getName().equals("")))

{

txt.setText("No file selected!");

} else {

// read file

try

{

BufferedReader reader = new BufferedReader(new FileReader(fileName.getAbsolutePath()));

String line = reader.readLine();

while(line != null)

{

Polynomial poly = new Polynomial(line);

polynomials.add(poly);

txt.setText(txt.getText() + poly.toString() + "\n");

line = reader.readLine();

}

reader.close();

// check ordered

boolean res = OrderedList.checkSorted(polynomials);

txt.setText(txt.getText() + "Polynomials sorted: " + res + "\n");

}

catch(IOException ex)

{

// nothing

} catch (InvalidPolynomialSyntax e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

}

}

});

f.add(btn);

f.setSize(400,500);

f.setLayout(null);

f.setVisible(true);

}

}