Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.android.myapplication;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import java.util.ArrayList;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ArrayList<Student> students = new ArrayList<>();
- students.add(new Student("John", 20));
- students.add(new Student("Jim", 15));
- students.add(new Student("Ann", 18));
- students.add(new Student("John", 14));
- ArrayList<Student> studentsSumTotal = new ArrayList<>();
- String prevStudentName = students.get(0).name;
- int prevStudentScore = students.get(0).score;
- for (int i = 1; i < students.size(); i++) {
- String currentName = students.get(i).name;
- int currentScore = students.get(i).score;
- if (currentName == prevStudentName) {
- int totalScore = currentScore + prevStudentScore;
- studentsSumTotal.add(new Student(currentName, totalScore));
- } else {
- studentsSumTotal.add(new Student(currentName, currentScore));
- }
- }
- Log.v("=================== Msg", "Sum of Score ===================");
- // Display Sum of Score for each student
- for (int i = 0; i < studentsSumTotal.size(); i++) {
- Log.v(studentsSumTotal.get(i).name, studentsSumTotal.get(i).score + "");
- }
- Log.v("=================== Msg", "Sum of Score ===================");
- Log.v("Size of studio", studentsSumTotal.size() + "");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement