2013-10-16 96 views
0

我需要这方面的帮助。我需要存储的标准值,以备后用.. 例如..我打字Java软件商店的输入值

  • 标准(1):测验
  • 百分比:25

  • 标准(2):出席
  • 百分比:75

然后程序会问

  • 学生姓名:JavaStack
  • 级为标准1(这是测验):92.52
  • 级的Criteria2(这是出席):86.35

我知道怎么做剩下的,但我不知道如何让标准值存储起来用于剩下的部分分级表现。

System.out.println("How many criteria?"); 
    System.out.print("Answer: "); 
    crit1=Integer.parseInt(inpt.readLine()); 

    String critr; 
    int perc; 

    for(int crit=1; crit<=crit1; crit++){ 

     if(crit1==1){ 
      System.out.println("Criteria(1): "); 
      critr=inpt.readLine(); 
      System.out.println("Percentage: 100%"); 
      perc=100; 
     } 

     System.out.print("Criteria("+ crit +"): "); 
     critr=inpt.readLine(); 

     System.out.println("Input between 1-100 only"); 
     System.out.print("Percentage: "); 
     perc=Integer.parseInt(inpt.readLine()); 
    } 


    int grade; 
    for(int name1=1; name1<=stud; name1++){ 
     System.out.println("Student's Name: "); 
     name=inpt.readLine(); 

     System.out.println("Grade for " +critr+": "); 
     grade=Integer.parseInt(inpt.readLine()); 
    } 

是的,这是一个学校的工作,我真的需要帮助。我希望你能帮助我。 在此先感谢!美好的一天。

+0

我很困惑。您已经将'Criteria values'存储在'critr'中。您正在覆盖它,但您仍然在存储它。 –

+0

你可以将它们写入数组。 –

+0

@ Justin - 是的,我知道我在覆盖它,但我需要存储从它输入的值,然后覆盖它。 @David - 我实际上正在考虑在数组中做这件事,但我可以问用户是否可以输入数组值?谢谢。 我是Java新手,所以请对我轻松一点。 – user2768501

回答

0

创建一个自定义类的阵列来存储数据

class Criteria { 

    public Criteria (String name, float weight) { 
     this.name = name; 
     this.weight = weight; 
    } 

    public String name; 
    public float weight 
} 

System.out.println("How many criteria?"); 
System.out.print("Answer: "); 
int critCount =Integer.parseInt(inpt.readLine()); 

Criteria[] sections = new Criteria[critCount]; 

for(int crit=0; crit < critCount; crit++){ 

    System.out.println("Criteria(1): "); 
    String name = inpt.readLine(); 
    System.out.println("Percentage: 100%"); 
    float value = Float.parseFloat(inpt.readLine()); 

    sections[i] = new Criteria(name, value); 
} 

// ...