JAVA
Write Java application to write/read serialized objects of class
Account: AccNo(int),
AccName(String), AccBalance(float). Develop a look-and-feel GUI
(Swing or
JavaFX) for this application.
package file;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.ArrayList;
import javax.swing.*;
class Account implements Serializable
{
private static final long serialVersionUID = 1L;
private int accNo;
private String accName;
private float accBalance;
Account()
{
accNo = 0;
accName = "";
accBalance = 0.0f;
}
Account(int accno, String name, float balance)
{
accNo = accno;
accName = name;
accBalance = balance;
}
@Override
public String toString()
{
return "\n\n Account Number:" + accNo + "\n Name: " + accName
+ "\n Account Balance: " + accBalance;
}
}
class ReadWriteOperation implements ActionListener
{
JFrame jf;
JPanel panel1, panel2, mainP;
JLabel accL, nameL, balanceL;
JTextField accT, nameT, balanceT;
JButton saveB, loadB, exitB;
ReadWriteOperation()
{
jf = new JFrame("Bank Account");
panel1 = new JPanel();
panel2 = new JPanel();
mainP = new JPanel();
accL = new JLabel("Enter Account Number: ");
nameL = new JLabel("Enter Account Name: ");
balanceL = new JLabel("Enter Initial Balance: ");
accT = new JTextField(10);
nameT = new JTextField(10);
balanceT = new JTextField(10);
saveB = new JButton("SAVE");
loadB = new JButton("LOAD");
exitB = new JButton("EXIT");
saveB.addActionListener(this);
loadB.addActionListener(this);
exitB.addActionListener(this);
panel1.add(accL);
panel1.add(accT);
panel1.add(nameL);
panel1.add(nameT);
panel1.add(balanceL);
panel1.add(balanceT);
panel1.setLayout(new GridLayout(3, 2));
panel2.add(saveB);
panel2.add(loadB);
panel2.add(exitB);
mainP.add(panel1);
mainP.add(panel2);
mainP.setLayout(new GridLayout(2, 1));
jf.add(mainP);
jf.setVisible(true);
//jf.setSize(300, 300);
jf.pack();
jf.setLocationRelativeTo(null);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ee)
{
if(ee.getSource() == saveB)
writeFile();
else if(ee.getSource() == loadB)
readFile();
else if(ee.getSource() == exitB)
System.exit(0);
}
void writeFile()
{
try
{
Account acc = new Account(Integer.parseInt(accT.getText()),
nameT.getText(), Float.parseFloat(balanceT.getText()));
ObjectOutputStream o = new ObjectOutputStream(
new FileOutputStream(new File("accountInfo.txt"), true));
// Write objects to file
o.writeObject(acc);
o.close();
}
catch (FileNotFoundException e)
{
System.out.println("File not found");
}
catch (IOException e)
{
System.out.println("Error initializing stream");
}
}
void readFile()
{
try
{
FileInputStream f = new FileInputStream("accountInfo.txt");
ObjectInputStream oi = new ObjectInputStream(f);
ArrayList<Account> acc = new ArrayList<Account>();
acc.add((Account)oi.readObject());
JOptionPane.showMessageDialog(jf, acc,
"Account Information", JOptionPane.INFORMATION_MESSAGE);
oi.close();
/*for(int c = 0; c < acc.size(); c++)
JOptionPane.showMessageDialog(jf, acc.get(c),
"Account Information", JOptionPane.INFORMATION_MESSAGE);*/
}
catch (FileNotFoundException e)
{
System.out.println("File not found");
}
catch (IOException e)
{
System.out.println("Error initializing stream");
}
catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class SerializedReadWriteAccount
{
public static void main(String ss[])
{
new ReadWriteOperation();
}
}
JAVA Write Java application to write/read serialized objects of class Account: AccNo(int), AccName(String), AccBalance(float). Develop a...
JAVA Write an application to test the HuffmanTree class. Your application will need to read a text file and build a frequency table for the characters occurring in that file. Once that table is built create a Huffman code tree and then a string consisting of 0 and 1 characters that represents the code string for that file. Read that string back in and re-create the contents of the original file. Prompt the user for file name. Read the file,...
FIX THE FOLLOWING JAVA CODE
public class Errors public static main(String[] args) { float sum int a = 27.5, b = 72.99; suma(a, b); System.out.println("Suma = %7:3b", sum); } //end main public static suma(float a, double b) { double suma suma = a + b; } }//end class
struct Item { string name; int quantity; float cost; }; const int MAX_SIZE = 50; class ManageInventory { public: ManageInventory() : count{0}, p_pInventoryItems {new Item*[size]} { } ManageInventory(int size) : size{size}, count{0}, p_pInventoryItems {new Item*[size]} { } ~ManageInventory(); void addItem(string name, int quantity, float cost); private: int size {MAX_SIZE}; int count; Item ** p_pInventoryItems; }; Write the definition for addItem. Use the new operator to dynamically create instances of type Item. Store pointers to inventory items in the inventoryItems array....
java
# 5 (to be finished later) Develop at application with GUI that will be calculating volume of a cylinder in cubic centimeters (see Day 2, practice exercise 2 and feel free to use the program you worked on). 1) Start with the layout. Plan the entry field, plan the buttons layout. Feel free to use this picture (to make it more appealing to the user): eds.l
Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...
JAVA How to add array to develop a contact list application for the person class objects developed in this code? The application will include functionality to add, remove, sort and search the contact list. You should also include a method to output the contents of a contact searched for, and also to output the entire list. The code: package BankProg; public class personal { private String facebook; public personal() { } public personal(String facebook) { this.facebook...
You will be designing and creating a Java GUI-based course application. Create a “Student” class. You need to have at least 3 instance variables (student characteristics like name,…), at least 2 constructors (1 should be a no-arg constructor), set and get methods. Create a “Course” class that consists of 2 instance variables: the course name and an array of Students (using your Student class). Design and create a JavaFX-based GUI interface that allows you to : INPUT information for Course...
JAVA City Files Program: Deserialize objects from a file. Print the data contained in the fields of the objects to a plaintext file. The Cities.dat binary file contains TEN serialized City objects. Each City object has name, population, latitude, and longitude fields. Prior to being serialized into the file, all ten objects had their fields set. City Java: public class City implements Serializable { private String name; private int population; private double latitude; private double longitude; public City(String n, int...
This assignment involves 2 Java programs 1) Write a Java program to read a CSV (Comma separated values) text file. The text file will contain comma separated values in each line. Each line contains data in this format: String(20), String(5),String(10), double. There will be multiple lines with each line containing the same number of values. Ask the user to enter the path for the CSV file for reading the file. After reading the data from the file output the data...
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...