Skip to the posts
Buffalo's neighborhood journals since 2003 🍀 Patrick Spicy Devil Logan🌭 Sahlen🥨 Weber Spank🥟 Pierogi🐸 Scaj🍺 Labatt Utica Pink Cherio❄️ Snow Murder

paul’s journal

Does this seem like advanced Java, lol?

· · 🌡️ 26°F

Still sitting in java class. I swear this is as procedural as it gets. I followed the instructions exactly.

package lab_04c;

/**
 *
 * @author visco
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       
        System.out.println("Student Score Grade");
         
        int[] scores = {76,91,80,55,71,98,70,88,69,60};
        String[] names = {
            "Suzie Q",
            "Peggy Forsnacht",
            "Boy George",
            "Flea",
            "Captain Hook",
            "Nelson Mandela",
            "he Might Thor",
            "Oedipa Maas",
            "Uncle Sam",
            "The Tick"};

        String[] grades = new String[scores.length];
        System.out.println("Name	Grade	Score");

        for(int x=0;x<scores.length;x++){
            
            int score = scores[x];
            String grade = "";
            
            if(score < 60){
                grade = "F";
            } else if (score < 70){
                grade = "D";
            } else if (score < 80){
                grade = "C";
            } else if (score < 90){
                grade = "B";
            } else {
                grade = "A";
            }
            grades[x] = grade;
            
            System.out.println(names[x]+"	"+score+"	"+grade);
            
        }
        
        String[] possibleGrades = {"A", "B", "C", "D", "F"};
        int[] frequency = {0,0,0,0,0};
        double total=0;
        
        Student: for(int student=0;student<scores.length;student++){
           Grades: for(int g=0;g<possibleGrades.length;g++){
               if(grades[student] == possibleGrades[g]){
                   frequency[g]++;
               }
           }
           
           total += scores[student];
        }
        
        System.out.println("
Statistics:");
       
        for(int g=0;g<possibleGrades.length;g++){
            System.out.println("Total "+possibleGrades[g]+"s: "+frequency[g]);
        } 

        System.out.println("
The mean score was : "+(total/scores.length));
    }

}

197 words

💬 3 comments

  1. paul ·

    I am doing the optional labs now, they a more interesting. Compressing RNA sequences with bit shifting. I swear it sounds sexier than it is.
  2. carolinian ·

    I'd say that PHP's array_push($myArray, $myValue) is about procedural as it gets.

    Though the above java code runs a close second.
  3. jbeatty ·

    Seems pretty advanced to me!

💬 Write a comment