Java编程问题 [英] Java programming Problem

查看:117
本文介绍了Java编程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题1:

编写一个Java程序,该程序将保留学生的记录.

学生班
该程序应包含带有以下字段的学生"类:
名称
ID
地址
Cgpa

学生记录课
您需要编写一个"StudentRecord"类.在"StudentRecord"类中,您必须声明"Student"类实例的数组"StudentArray". "StudentRecord"类包含以下方法,这些方法可以使用Student类的实例来操纵"StudentArray":
AddRecord:AddRecord方法将新的学生记录添加到StudentArray的数组的下一个可用空索引处.如果阵列已满,则应调整阵列的大小并添加新记录.
PrintRecord:PrintRecord方法根据其名称按字母顺序对StudentArray进行排序.如果有平局(即,如果多个学生的名字相同),则根据其ID对其进行排序.排序后,此方法将输出StudentArray的内容(名称,ID,地址,CGPA),每条记录均在一行中.
DeleteRecord:DeleteRecord方法要求用户输入要删除的学生的ID号.然后,删除该记录并报告(通过打印消息)删除的成功和失败.删除完成后,您的程序将显示一条消息"ID ####被删除".如果给定的ID不存在,您的程序将显示一条消息"ID ####不存在".一旦删除了一条记录,DeleteRecord方法还将向左移所有已删除记录右侧的记录.
编辑记录:EditRecord方法要求用户输入学生ID并编辑其相应的信息(名称,CGPA,地址).如果给定的ID不存在,您的程序将显示一条消息"ID ####不存在". EditRecord方法应该能够编辑该学生的一个或多个信息.
测试人员课程
您的程序应具有包含主要方法的"TesterClass".在主要方法中,您的程序应打印以下消息:
输入1以添加记录
输入2以打印记录
输入3以删除记录
输入4以编辑记录
如果用户选择1,则程序将向StudentArray添加新的学生记录.如果用户选择2,则程序将按字母顺序打印学生列表.如果用户选择3,则程序将删除给定ID的记录.如果用户选择4,则程序将编辑给定ID的记录.
完成一项操作后(在1-4中选择一个选项),您的命令行菜单将询问用户是否要继续执行该程序.如果用户按"Y"/"y",则将再次为用户提供菜单1-4.否则,用户将退出程序.



问题2:


编写一个Java程序,以读取文本文件"Student.txt",其中包含带有姓名,ID和地址字段的学生信息(一行包含一个学生的信息).然后,您的程序将读取这些数据,并将其保存在学生类数组中.学生班级包含名称,ID和地址作为其字段.最后,您的程序从数组中读取每个条目,并将数据写入新文件"Object.txt"中.

您应该从命令行获取输入和输出文件名.如果未从命令行传递文件名,则提示用户输入文件名.
•使用适当的消息处理特定的异常"FileNotFoundException".
•使用FileInputStream/FileOutputStream类执行程序.抱歉,这里没有快速提问.这听起来像是您的大学项目/作业,您应该付出一些努力.

我们希望您花一些时间来尝试解决您面临的问题,然后再花一些时间在此处发布问题时提出问题.

这是询问者的期望:
1. 先尝试您要做什么!
2.制定看起来像问题/无法解决的问题.

试试看,告诉他们是否遇到问题.
成员将很乐意为您提供帮助.


Question 1 :

Write a Java program that will keep the records of students.

Student Class
The program should contain a "Student" class with the following fields:
Name
Id
Address
Cgpa

Student Records Class
You need to write a "StudentRecord" class. In the "StudentRecord" class, you have to declare an array "StudentArray" of the instance of the "Student" class. The "StudentRecord" class contains the following methods that can manipulate the "StudentArray" with the instances of the Student class:
AddRecord: The AddRecord method adds a new student record to the StudentArray at the next available empty index of the array. If the array is full, then you should resize the array and add the new record.
PrintRecord: The PrintRecord method sorts the StudentArray in alphabetical order according to their names. If there is a tie (i.e., if multiple students have the same name), then sort them according to their id’s. After sorting, this method prints the contents (Name, Id, Address, CGPA) of the StudentArray, each record in a line.
DeleteRecord: The DeleteRecord method asks the users to enter the Id number of a student to be deleted. Then, delete that record and reports (by printing a message) the success and failure of the deletion. After completion of a deletion, your program will show a message "ID #### is deleted". If the given Id does not exist, your program will show a message "ID #### does not exist". Once, a record is deleted, the DeleteRecord method also shift left all records that are to the right of the deleted record.
Edit Record: The EditRecord method asks the user to enter a student Id and edits its corresponding information (name, cgpa, address). If the given Id does not exist, your program will show a message "ID #### does not exist". EditRecord method should be able to edit one or more information of that student.
Tester Class
Your program should have a "TesterClass" containing the main method. In the main method, your program should print the following message:
Enter 1 to Add a Record
Enter 2 to Print the Records
Enter 3 to Delete a Record
Enter 4 to Edit a Record
If the user chooses 1, then the program will add a new student record to the StudentArray. If the user chooses 2, then the program will print the student list in alphabetical order. If the user chooses 3, then the program will delete the records of the given Id. If the user chooses 4, then the program will edit the records of the given Id.
Upon the completion of one operation (choosing one option among 1 – 4), your command line menu will ask the user whether s/he wants to continue the program. If the user press "Y"/"y", then the user will be given menu 1 – 4 again. Otherwise the user will quit the program.



Question 2 :


Write a java program that reads a text file ‘Student.txt’ containing Students information with name, id and address field (one line contains information of one student). Then, your program reads these data and save them in an array of Student Class. The Student Class contains name, id and address as its fields. Finally, your program reads each entry from the array and the write the data in the new file ‘Object.txt’.

You should take the input and output file name from the command line. If the file names are not passed from the command line, prompt the user for the file name.
• Handle the specific exceptions ‘FileNotFoundException’ with proper massages.
• Do the program using FileInputStream/FileOutputStream classes.

解决方案

It does not work like this here. I am sorry but there is no quick question here. This sounds like your college project/assignment, you should put some effort.

We expect you to put some time in trying the issue that you are facing and then some time in formulating the question while posting here.

Here is what is expected by enquirers:
1. TRY first what you want to do!
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.


这篇关于Java编程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆