进入类对象时Arraylist中的冗余

时间:2016-04-10 17:37:44

标签: java arrays object arraylist redundancy

让我们在使用Java的软件包中说我们正在使用4个文件。第一个说 StudentModel.java ,第二个说 studentView.java ,第三个 studentController.java 和第四个 studentMain.java

现在 studentMain.java 的结构是:

 package student;

 import java.util.*;
 import java.io.*;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;

 public class studentController {
           private studentModel model;
           private studentView view ;

 public studentController(studentModel model, studentView view){
  this.model = model;
  this.view = view;
 }

 public void show(){
  this.view.display(this.model);
 }
 public void show_for_all(){
    this.view.display_for_all(this.model);
 }
 public void input(){
        String name;//name of student
        int roll;   //roll of student
        String date;        
        int marks[]=new int [6];
        String sub[]=new String[6];
        Scanner s = new Scanner(System.in);
        int m,j;String s1;int fg=0;
        System.out.println("\t\t ENTER DETAILS OF STUDENT");
        System.out.print("Enter name:");
        name=s.nextLine();

        /*to check if a string contains digits or not*/
        for(int h=0;h<name.length();h++){
        if(name.charAt(h)=='1' || name.charAt(h)=='2'||name.charAt(h)=='3'||name.charAt(h)=='4'||name.charAt(h)=='5'||name.charAt(h)=='6'||name.charAt(h)=='7'||name.charAt(h)=='8'||name.charAt(h)=='9'){
            fg=1;
            System.out.println("name contains digits enter correctlty");
            break;
        }
    }
    if(fg!=1){
        System.out.print("Enter roll no:");
        roll=s.nextInt();
        System.out.println();
        /*system generated date*/
        SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//dd/MM/yyyy
            Date now = new Date();
            date = sdfDate.format(now);
        System.out.println("Admission Date : "+date);
        System.out.println("Enter Subject and marks :");
        /*entering the marks of the subjects*/
        for(j=0;j<5;j++){
            s1=s.next();
            m= s.nextInt();
            if(m<0 || m>100){         //marks should not > 100 or <0
                System.out.println("wrong marks entered");break;}
            sub[j]=s1;
            marks[j]=m;
            //total=total+m;
        }
        model.set_name(name);
        model.set_roll(roll);
        model.set_date(date);
        model.set_sub_marks(marks,sub);
        model.set_total();
        model.set_cgpa();
    }

  } 
       public boolean compare_roll(int rol){
          if(this.model.get_roll()==rol)
                return true;
          else 
                return false;
          }
        /*function to change the marks of any of the subjects of a  particular student*/
     public void change_marks(){
       int f,sub_code,new_marks;
      System.out.println("enter no of subjects whose marks needs to be changed");
       Scanner s = new Scanner(System.in);
       f=s.nextInt();
     while(f!=0){
        System.out.println("Enter subject codes : ");       
        sub_code=s.nextInt();   
        if(sub_code>=1 && sub_code<=5){
             System.out.println("Enter new marks");
            new_marks=s.nextInt();
            if(new_marks>=0&&new_marks<101)
            model.change_marks(sub_code,new_marks);
            else
            System.out.println("Marks OUT of Range of 0 to 100");
            }
        else
            System.out.println("Wrong subject code entered");
        f--;
      }
  }


 };

studentController.java 的结构是:

$query = "SELECT * FROM project WHERE ".$searchtype." LIKE '%".$searchterm."%'";

$result = mysqli_query($link,$query) or die("Line ".__LINE__." Error found: ".mysqli_error($link)); // If there's an error, it should show here.

在输入数据的新条目时,我遇到了问题。在为学生输入第一 条目时, 问题。当我输入第二次 条目的学生详细信息时,首先详细信息 条目正在删除。由于第二名学生的详细信息被复制到第一位学生,因此存在冗余。

为了更好的解释,我包括截图:

Details of the First Student Printed

这意味着第一个条目已正确输入并存储。

Printing the details of all the students

如果您看到最后一个屏幕截图,您会看到第一个学生的详细信息已被第二个学生的详细信息所取代。因此存在冗余。

0 个答案:

没有答案