Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

how write this in my code can you Can you write it : In order to add a train to the Train.txt file, the admin

how write this in my code can you Can you write it: In order to add a train to the "Train.txt" file, the admin needs to enter an id. The id is
unique, so before adding the train we need to check if there is no other train in the file
with the same id.
The Admin should choose two different stations and define the maximum number of
passengers that could take the train
/*
*
*/
package com.mycompany.login;
import java.awt.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import javax.swing. *;
/**
*
* @author Haya2
*/
public class Train extends JFrame {
private JButton b1,b2;
private JTextField t1,t2 ;
private JLabel l1,l2,l3,l4;
private JComboBox cmb1,cmb2;
public Train (String title) {
super(title);
this.setVisible(true);
this.setSize(3000, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
l1=new JLabel("Train id");
t1=new JTextField(10);
JPanel p1= new JPanel(new FlowLayout(FlowLayout.LEFT));
p1.add(l1);
p1.add(t1);
l2=new JLabel("departure station");
String[] st ={"Buraydah,Riyadh,Jaddah"};
cmb1= new JComboBox(st);
JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT));
p2.add(l2);
p2.add(cmb1);
l3=new JLabel("arrival station");
String[] st1 ={"Buraydah,Riyadh,Jaddah"};
cmb2= new JComboBox(st);
JPanel p3=new JPanel(new FlowLayout(FlowLayout.LEFT));
p3.add(l3);
p3.add(cmb2);
l4=new JLabel("Max Passengers");
t1=new JTextField(10);
JPanel p4= new JPanel(new FlowLayout(FlowLayout.LEFT));
p4.add(l4);
p4.add(t2);
b1= new JButton("add");
b2= new JButton("Cancel");
JPanel p5= new JPanel();
p5.add(b1);
p5.add(b2);
JPanel p=(JPanel)this.getContentPane();
p.setLayout(new GridLayout(5,1));
p.add(p1);
p.add(p2);
p.add(p3);
p.add(p4);
p.add(p5);
this.pack();
this.setVisible(true);
}
public static void main(String[] args) {
// TODO code application logic here
Train r = new Train("add Train");
}
}
image text in transcribed
2. The class Train: Implement the class Train implementing Serializable. All the Objects of this class will be stored in the file "Train.txt". 3. The class Admin: The "Add Train" GUI is described as follows: In order to add a train to the "Train.txt" file, the admin needs to enter an id. The id is unique, so before adding the train we need to check if there is no other train in the file with the same id. The Admin should choose two different stations and define the maximum number of passengers that could take the train. Otherwise, if the departure station and the arrival station are equal or the "Max Passengers" is not specified, the following message will appear: If all the inputs fields are well and correctly given, an Object Train will be added to the file and a message will appear by the system

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions