0% found this document useful (0 votes)
24 views6 pages

Assignment Java

The document outlines two Java programming assignments: a Student Report Card Generator and a Coffee Machine Simulation. The first assignment involves creating a program to store student details, calculate average marks, assign grades, and check pass/fail status, while the second assignment focuses on simulating a coffee shop where multiple customers can place orders for different types of coffee using threads. Each assignment includes step-by-step instructions and pseudocode to guide the implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views6 pages

Assignment Java

The document outlines two Java programming assignments: a Student Report Card Generator and a Coffee Machine Simulation. The first assignment involves creating a program to store student details, calculate average marks, assign grades, and check pass/fail status, while the second assignment focuses on simulating a coffee shop where multiple customers can place orders for different types of coffee using threads. Each assignment includes step-by-step instructions and pseudocode to guide the implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

✅ Assignment 1: Student Report Card Generator

🎯 Goal:

Create a Java program that can:

● Store a student’s name, roll number, and marks for 5 subjects.

● Calculate their average marks.

● Decide their grade (A, B, C, D).

● Check if the student has passed or failed.

● Print a report card with all this information.

📚 Topics you'll practice:

● Variables and data types

● Arrays

● If-else conditions and loops

● Classes and objects

● Inheritance

● Methods

👩‍💻 What to do step by step:

1. Create a class named Student:

o It should have:

▪ name (String)

▪ rollNumber (int)

▪ marks[] (array of 5 integers)

o Add a constructor to assign these values.

o Write a method displayDetails() to print the name and roll number.

o Write a method calculateAverage() to find average marks.


o Write a method getGrade():

▪ If average >= 90 → Grade A

▪ If average >= 80 → Grade B

▪ If average >= 70 → Grade C

▪ Otherwise → Grade D

2. Create another class named Result that extends Student:

o Add a method checkPassFail():

▪ If all subject marks are 35 or more → Pass

▪ Otherwise → Fail

o Override displayDetails() to:

▪ Also show marks, average, grade, and Pass/Fail

3. In the main() method:

o Create an object of the Result class.

o Use Scanner to take input from the user (name, roll number, and 5 subject marks).

o Call the appropriate methods to calculate and display the full report card.

✅ Example Output:

Enter Name: Ananya

Enter Roll Number: 101

Enter Marks for 5 Subjects:

78 85 90 65 88

--- Student Report Card ---

Name: Ananya

Roll Number: 101

Marks: 78 85 90 65 88

Average: 81.2
Grade: B

Result: Pass

Certainly! Here's the Coffee Machine Simulation explained in the same style as Assignment 1:
Student Report Card Generator, with a clear use case and concepts:

Certainly! Here’s the complete version of the assignment with a clear “What to do – Step by Step”
section, similar to Assignment 1.

✅ Assignment 2: Coffee Machine Simulation

📝 Use Case:

Imagine a small coffee shop that serves three types of coffee: Espresso, Latte, and Cappuccino.
Each customer walks in, places an order, and the machine prepares and serves it.
Multiple customers can place orders at the same time — so the machine should be able to handle
them simultaneously.

We will model this scenario using Java classes and features.

🧭 What to Do – Step by Step

✅ Step 1: Define Coffee Types

● Think of the coffee shop menu: it has 3 fixed options.

● Define a list of these fixed coffee types.

● Use a Java feature that allows defining fixed constant values (hint: enum).

✅ Step 2: Design a Generic Coffee Machine

● Imagine you’re designing a blueprint or template that any coffee machine will follow.

● Use an abstract class to define:

o A way to accept a coffee type

o An abstract method to prepare coffee (but don’t implement it yet)

o A method implementation to serve coffee (can be same for all)


✅ Step 3: Create a Working Coffee Machine

● Now implement a real coffee machine by extending the abstract class.

● In this class:

o Prepare the coffee based on the type selected.

o Print messages to indicate preparation and serving.

✅ Step 4: Model the Customer

● A customer wants a particular coffee.

● Each customer will:

o Have a name

o Choose a coffee type

o Place an order using the coffee machine

✅ Step 5: Handle Multiple Customers

● Use threads to simulate multiple customers ordering at the same time.

● Each customer runs in a separate thread, places an order, and receives the coffee.

✅ Step 6: Run the Simulation

● In your main program:

o Create 2–3 customers with different names and coffee choices.

o Start their threads.

o Observe how coffee orders are prepared and served, possibly in a different order.

Pseudocode

Sure! Here's the pseudocode for Assignment 2: Coffee Machine Simulation, written in a simple and
structured way for first-year engineering students to understand.
🧾 Pseudocode for Coffee Machine Simulation

1. Define Coffee Types (Enum-like structure)

Define CoffeeType as a fixed list:

- ESPRESSO

- LATTE

- CAPPUCCINO

2. Create Abstract Coffee Machine

Define abstract class CoffeeMachine:

- Method: prepareCoffee(coffeeType) [abstract, to be implemented by child]

- Method: serveCoffee(customerName, coffeeType)

Print: "Serving [coffeeType] to [customerName]"

3. Create Real Coffee Machine

Define class MyCoffeeMachine extends CoffeeMachine:

- Implement method: prepareCoffee(coffeeType)

Print: "Preparing [coffeeType]"

Wait for 2 seconds (simulate time delay)

Print: "[coffeeType] is ready"

4. Define Customer as a Thread

Define class Customer implements Runnable:

- Properties:

- name

- coffeeType

- coffeeMachine
- Method: run()

Print: "[name] is placing an order for [coffeeType]"

Call: [Link](coffeeType)

Call: [Link](name, coffeeType)

5. Main Program

In main:

- Create an instance of MyCoffeeMachine

- Create multiple customers (e.g., 3), each with:

- name

- coffeeType

- shared coffeeMachine instance

- For each customer:

- Create a thread with that customer

- Start the thread

✅ What Will Happen:

● Multiple customers will place orders at the same time.

● The coffee machine will prepare and serve them.

● The output order may vary depending on thread scheduling.

You might also like