From d7389e15a86b2c9d6a35c578c325ee2c0dfa3926 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 7 Nov 2021 17:34:47 -0800 Subject: task 16: addressing sejo's feedback I'm still not quite happy with this.. --- tutorial/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tutorial/index.md') diff --git a/tutorial/index.md b/tutorial/index.md index c19af1ee..48173fbb 100644 --- a/tutorial/index.md +++ b/tutorial/index.md @@ -609,14 +609,14 @@ for a really complex example of this sort of _procedural graphics_. ## Task 16: a simple app -We now know how to read keys from keyboard and draw on the screen. Look at +We now know how to read keys from keyboard and draw on the screen. Try out [tutorial/counter.mu](https://github.com/akkartik/mu/blob/main/tutorial/counter.mu) which implements a simple counter app. screenshot of the counter app -Do all the parts make sense? Read the extensive vocabulary of functions for -[drawing text to screen](https://github.com/akkartik/mu/blob/main/vocabulary.md#printing-to-screen). +Now look at its code. Do all the parts make sense? Reread the extensive +vocabulary of functions for [drawing text to screen](https://github.com/akkartik/mu/blob/main/vocabulary.md#printing-to-screen). --- -- cgit 1.4.1-2-gfad0 log tree commit diff stats
path: root/requirements.txt
blob: 411a2a97f71ad703400f0086b8b59c550ff01701 (plain) (blame)
1
2
3
/smlckz/zadania/plain/java/code/StudentsArray.java?h=main&id=fc765a85e5de17a29e4339f888e2497408776824'>plain) (tree)


























































































                                                                                            
import java.util.*;

class Subject {
    String title;
    int theory;

    Subject(String title, int theory) {
        this.title = title;
        this.theory = theory;
    }

    static Subject input(Scanner sc) {
        System.out.println("Enter details of subject:");
        System.out.print("Enter title: ");
        String title = sc.nextLine();
        System.out.print("Enter theory marks: ");
        int theory = sc.nextInt();
        sc.skip("\n");
        return new Subject(title, theory);
    }
    int getTheoryMarks() { return theory; }

    void display() {
        System.out.println("  Marks obtained in " + title + ": " + theory);
    }
}

class Student {
    final static int SUBJECT_COUNT = 3;
    long roll;
    String name;
    String stream;
    Subject[] subjects;

    Student(long roll, String name, String stream, Subject[] subjects) {
        this.roll = roll;
        this.name = name;
        this.stream = stream;
        this.subjects = subjects;
    }

    static Student input(Scanner sc) {
        System.out.println("Enter the details of the student:");
        System.out.print("Enter Roll no.: ");
        long roll = sc.nextLong();
        sc.skip("\n");
        System.out.print("Enter name: ");
        String name = sc.nextLine();
        System.out.print("Enter stream: ");
        String stream = sc.nextLine();
        Subject[] subjects = new Subject[SUBJECT_COUNT];
        for (int i = 0; i < subjects.length; i++) {
            System.out.print("For subject " + (i + 1) + ": ");
            subjects[i] = Subject.input(sc);
        }
        return new Student(roll, name, stream, subjects);
    }

    void display() {
        System.out.println("Student details:");
        System.out.println("  Roll No.: " + roll);
        System.out.println("  Name: " + name);
        System.out.println("  Stream: " + stream);
        int totalMarks = 0;
        for (Subject subject : subjects) {
            subject.display();
            totalMarks += subject.getTheoryMarks();
        }
        double average = ((double)totalMarks) / subjects.length;
        System.out.println("  Average percentage: " + String.format("%.2f", average) + "%");
    }
}

class StudentsArray {
    public static void main(String[] args) {
        var sc = new Scanner(System.in);
        System.out.println("Enter the number of students: ");
        Student[] students = new Student[sc.nextInt()];
        System.out.println("Enter the details of the students:");
        for (int i = 0; i < students.length; i++) {
            System.out.print("For student " + (i + 1) + ": ");
            students[i] = Student.input(sc);
        }
        System.out.println("Displaying the details of the students:");
        for (int i = 0; i < students.length; i++) {
            System.out.println("\nFor student " + (i + 1) + ": ");
            students[i].display();
        }
    }
}