Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Compiled class files
*.class

# Package Files
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# Virtual machine crash logs
hs_err_pid*

# IDE specific files
.idea/
*.iml
.vscode/
*.swp
*.swo
*~

# OS specific files
.DS_Store
Thumbs.db
210 changes: 210 additions & 0 deletions BasicStdtGrdr/BasicStdtGrdr.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
import java.util.ArrayList;
import java.util.Scanner;

/**
* BasicStdtGrdr - Basic Student Grader
*
* Features:
* - Input student names and five test scores
* - Calculates average score for each student
* - Assigns letter grade (A-F) based on average
* - Outputs formatted results table
*/
public class BasicStdtGrdr {

/**
* Main method - Entry point of the application
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Student> students = new ArrayList<>();

try {
displayWelcomeMessage();

// Get number of students
System.out.print("Enter number of students: ");
int numStudents = scanner.nextInt();
scanner.nextLine(); // Clear newline

// Input data for each student
for (int i = 0; i < numStudents; i++) {
System.out.println("\n--- Student " + (i + 1) + " ---");

System.out.print("Enter student name: ");
String name = scanner.nextLine();

double[] scores = new double[5];
System.out.println("Enter 5 test scores:");

boolean validScores = true;
for (int j = 0; j < 5; j++) {
System.out.print("Score " + (j + 1) + ": ");
scores[j] = scanner.nextDouble();

if (scores[j] < 0 || scores[j] > 100) {
System.out.println("Error: Score must be between 0 and 100! Please re-enter data for this student.");
validScores = false;
break;
}
}
scanner.nextLine(); // Clear newline

if (!validScores) {
i--; // Retry this student
continue;
}

Student student = new Student(name, scores);
students.add(student);
}

// Display results
displayResults(students);

} catch (Exception e) {
System.err.println("Error: Invalid input. Please enter valid data.");
} finally {
scanner.close();
}
}

/**
* Displays welcome message
*/
private static void displayWelcomeMessage() {
System.out.println("=========================================");
System.out.println(" Basic Student Grader System ");
System.out.println("=========================================");
System.out.println("This system calculates student averages");
System.out.println("and assigns letter grades (A-F).");
System.out.println();
}

/**
* Displays formatted results table for all students
*/
private static void displayResults(ArrayList<Student> students) {
System.out.println("\n\n=========================================");
System.out.println(" STUDENT GRADE REPORT ");
System.out.println("=========================================");

// Table header
System.out.printf("%-20s %-8s %-8s %-8s %-8s %-8s %-10s %-6s%n",
"Name", "Score1", "Score2", "Score3", "Score4", "Score5", "Average", "Grade");
System.out.println("=========================================================================================================");

// Print each student's data
for (Student student : students) {
double[] scores = student.getScores();
System.out.printf("%-20s %-8.1f %-8.1f %-8.1f %-8.1f %-8.1f %-10.2f %-6s%n",
student.getName(),
scores[0], scores[1], scores[2], scores[3], scores[4],
student.getAverage(),
student.getLetterGrade());
}

System.out.println("=========================================================================================================");

// Display statistics
displayStatistics(students);
}

/**
* Displays class statistics
*/
private static void displayStatistics(ArrayList<Student> students) {
if (students.isEmpty()) {
return;
}

double classTotal = 0;
double highest = students.get(0).getAverage();
double lowest = students.get(0).getAverage();

for (Student student : students) {
double avg = student.getAverage();
classTotal += avg;
if (avg > highest) highest = avg;
if (avg < lowest) lowest = avg;
}

double classAverage = classTotal / students.size();

System.out.println("\nClass Statistics:");
System.out.printf("Class Average: %.2f%n", classAverage);
System.out.printf("Highest Average: %.2f%n", highest);
System.out.printf("Lowest Average: %.2f%n", lowest);
System.out.println("=========================================");
}
}

/**
* Student class - Represents a student with scores and grade information
*/
class Student {
private String name;
private double[] scores;
private double average;
private String letterGrade;

/**
* Constructor to create a new student
*/
public Student(String name, double[] scores) {
this.name = name;
this.scores = scores;
this.average = calculateAverage();
this.letterGrade = calculateLetterGrade();
}

/**
* Calculates the average of the five scores
*/
private double calculateAverage() {
double sum = 0;
for (double score : scores) {
sum += score;
}
return sum / scores.length;
}

/**
* Determines the letter grade based on average
* A: 90-100
* B: 80-89
* C: 70-79
* D: 60-69
* F: Below 60
*/
private String calculateLetterGrade() {
if (average >= 90) {
return "A";
} else if (average >= 80) {
return "B";
} else if (average >= 70) {
return "C";
} else if (average >= 60) {
return "D";
} else {
return "F";
}
}

// Getters
public String getName() {
return name;
}

public double[] getScores() {
return scores;
}

public double getAverage() {
return average;
}

public String getLetterGrade() {
return letterGrade;
}
}
57 changes: 57 additions & 0 deletions BasicStdtGrdr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# BasicStdtGrdr (Basic Student Grader)

A student grading system that calculates averages and assigns letter grades.

## Features
- Input student names and five test scores
- Automatically calculates average for each student
- Assigns letter grades (A-F) based on average
- Displays formatted results table
- Shows class statistics (class average, highest, lowest)

## Grading Scale
- **A**: 90-100
- **B**: 80-89
- **C**: 70-79
- **D**: 60-69
- **F**: Below 60

## How to Compile
```bash
javac BasicStdtGrdr.java
```

## How to Run
```bash
java BasicStdtGrdr
```

## Usage Example
```
Enter number of students: 2
--- Student 1 ---
Enter student name: John Doe
Enter 5 test scores:
Score 1: 95
Score 2: 88
Score 3: 92
Score 4: 85
Score 5: 90

--- Student 2 ---
Enter student name: Jane Smith
Enter 5 test scores:
Score 1: 78
Score 2: 82
Score 3: 75
Score 4: 80
Score 5: 85
```

## Output
The program displays a formatted table showing:
- Student names
- All five scores
- Calculated average
- Letter grade
- Class statistics
69 changes: 68 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,68 @@
# java-Projects
# Java Mini-Projects Collection

This repository contains three Java mini-projects, each demonstrating fundamental programming concepts.

## Projects Overview

### 1. SimpleCalculator
A command-line calculator that performs basic arithmetic operations.
- **Location**: `SimpleCalculator/`
- **Features**: Addition, subtraction, multiplication, division with error handling
- **Key Concepts**: Switch statements, exception handling, user input
- **Lines of Code**: 127

[View SimpleCalculator Documentation](SimpleCalculator/README.md)

### 2. SimpleInventoryManager
A menu-driven inventory management system.
- **Location**: `SimpleInventoryManager/`
- **Features**: Add, view, update, and remove inventory items
- **Key Concepts**: Java Collections (ArrayList), object-oriented programming, menu-driven interface
- **Lines of Code**: 226

[View SimpleInventoryManager Documentation](SimpleInventoryManager/README.md)

### 3. BasicStdtGrdr (Basic Student Grader)
A student grading system with average calculation and letter grade assignment.
- **Location**: `BasicStdtGrdr/`
- **Features**: Student data input, average calculation, grade assignment, formatted output
- **Key Concepts**: Arrays, calculations, formatting, data structures
- **Lines of Code**: 198

[View BasicStdtGrdr Documentation](BasicStdtGrdr/README.md)

## How to Use

Each project is self-contained in its own directory. To compile and run any project:

```bash
cd <ProjectDirectory>
javac <ProjectName>.java
java <ProjectName>
```

For example, to run the SimpleCalculator:
```bash
cd SimpleCalculator
javac SimpleCalculator.java
java SimpleCalculator
```

## Requirements
- Java Development Kit (JDK) 8 or higher
- Command-line interface (Terminal/Command Prompt)

## Project Structure
```
java-Projects/
├── README.md
├── SimpleCalculator/
│ ├── SimpleCalculator.java
│ └── README.md
├── SimpleInventoryManager/
│ ├── SimpleInventoryManager.java
│ └── README.md
└── BasicStdtGrdr/
├── BasicStdtGrdr.java
└── README.md
```
Loading