0% found this document useful (0 votes)
21 views4 pages

Java Programming Projects Overview

Uploaded by

elasticnobel6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Java Programming Projects Overview

Uploaded by

elasticnobel6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROJECT FILE

Question 1- Introduction to Blue J

Question 2 – Java Programs-

Program 1-
Design a class name ShowRoom with the following description :

Instance variables/ Data members :


String name – To store the name of the customer
long mobno – To store the mobile number of the customer
double cost – To store the cost of the items purchased
double dis – To store the discount amount
double amount – To store the amount to be paid after discount

Member methods: –
void input() – To input customer name, mobile number, cost
void calculate() – To calculate discount on the cost of purchased items, based on following
criteria

Cost Discount (in percentage)

Less than or equal to ₹ 10000 5%

More than ₹ 10000 and less than or equal to ₹


10%
20000

More than ₹ 20000 15%

void display() – To display customer name, mobile number, amount to be paid after discount

Write a main method to create an object of the class and call the above member methods.
Program 2-
Define a class Student with the following specifications

Data Members Purpose

String name To store the name of the student

inteng To store marks in English

inthn To store marks in Hindi

intmts To store marks in Maths

double total To store total marks

doubleavg To store average marks

Member Methods Purpose

void accept() To input marks in English, Hindi and Maths

void compute() To calculate total marks and average of 3 subjects

void display() To show all the details viz. name, marks, total and average
Write a program to create an object and invoke the above methods.

Program 3

Write a program by using a class with the following specifications


Class name — Prime
Data members — private int n
Member functions:
1. void input() — to input a number
2. void checkprime() — to check and display whether the number is prime or not
Use a main function to create an object and call member methods of the class.

Program 4

Write a program to print the Fibonacci series upto 10 terms.


[A series of numbers in which each number is the sum of the two preceding numbers.

For example: 0,1,1,2,3, …………… n].


Program 5

Using the switch statement, write a menu driven program:

1. Palindrome number: (A number is a Palindrome which when read in reverse order is


same as in the right order)

Example: 11, 101, 151 etc.

2. To find the smallest digit of an integer that is input:


Sample input: 6524
Sample output: Smallest digit is 2
For an incorrect choice, an appropriate error message should be displayed.

Program 6

Write a program to input a number. Check and display whether it is a Niven number or not. (A
number is said to be Niven which is divisible by the sum of its digits).

Example: Sample Input 126


Sum of its digits = 1 + 2 + 6 = 9 and 126 is divisible by 9.

Program 7

Write a program to accept a number and check and display whether it is a spy number or not. (A
number is spy if the sum of its digits equals the product of its digits.)

Example : consider the number 1124.


Sum of the digits = l + l+ 2 + 4 = 8
Product of the digits = 1x1 x2x4 = 8

Program 8

Write a program to print the following pattern-

a) 54321
4321
321
21
1
b) Floyd’s triangle
1
23
456
7 8 9 10
11 12 13 14 15

Common questions

Powered by AI

The programming examples use both iteration and recursion to address different computational problems. Iteration is demonstrated in operations like generating the Fibonacci series and printing patterns such as Floyd’s Triangle , where loops are employed to repeat sequences of operations until certain conditions are met. Recursion might not be directly outlined in these examples, but it is a natural extension in problems like checking for prime numbers, where a recursive definition can elegantly simplify checking divisibility across a range of values. These paradigms showcase two fundamental approaches in programming, offering varied efficiency based on the context.

The use of a switch statement in the menu-driven program is suitable for implementing a simple decision-making process based on user input, offering a cleaner and more readable alternative to multiple if-else statements . It provides an intuitive framework for executing different code blocks based on the user's menu choice. However, its limitation lies in the inflexibility when dealing with more complex conditions or when the inputs are not discrete values. Moreover, a lack of detailed error handling can be a drawback unless additional logic is added to handle incorrect choices effectively.

The programming examples in the document demonstrate object-oriented principles, particularly encapsulation and modularity, through the use of classes and member functions. For example, the 'ShowRoom' class encapsulates customer details and discount calculations within instance variables and member methods like 'input()', 'calculate()', and 'display()' . Similarly, the 'Student' class contains encapsulated data members for storing marks along with methods to manipulate and display these data . This design pattern enhances modularity by separating the program logic into discrete units, each handling a specific aspect of the application, thus making the code more organized and manageable.

To generate the Fibonacci series up to a specified number, the algorithm involves initializing two numbers, often 0 and 1, which form the basis of the sequence. The process then iteratively adds these two numbers to get the next term, updating these variables repeatedly to display each number in the sequence. For example, in the document, a series starting with 0, 1 would proceed in the manner: 0, 1, 1, 2, 3, 5, and so on up to the pre-defined limit . This simple recursive relationship illustrates iterative programming and numeric series generation.

The 'ShowRoom' class uses conditional logic in its 'calculate()' method to apply discounts based on purchasing cost tiers. The method checks the cost against thresholds to determine the percentage discount — 5% for costs less than or equal to ₹ 10,000, 10% for costs between ₹ 10,001 and ₹ 20,000, and 15% for costs above ₹ 20,000 . This tiered discount system ensures that customers receive a fair discount relative to their purchase size, which can enhance customer satisfaction and potentially increase sales volumes.

The 'Student' class example integrates data encapsulation by defining private data members to store each student's marks, ensuring access to this data only via public methods. Arithmetic operations are then utilized in methods like 'compute()' to calculate total and average marks from the stored individual subject marks in English, Hindi, and Maths . This encapsulated processing of educational data illustrates how object-oriented design can streamline data handling, allowing separation of concerns by maintaining data integrity and focusing on specific computational tasks.

To identify the smallest digit of an integer, iterative logic is applied to isolate and compare each digit sequentially, updating the smallest recorded value accordingly. This comparison continues until all digits have been evaluated, with the smallest being displayed at the end . For error handling in the menu-driven program, an additional default case in the switch statement provides a way to address incorrect choices by displaying an appropriate error message to guide user input, thereby ensuring the program remains robust and user-friendly even with invalid inputs.

A 'Niven number' is determined by calculating the sum of its digits and checking if the original number is divisible by this sum. For instance, for the input number 126, its digits sum up to 9, and since 126 is divisible by 9, it is a Niven number . This concept emphasizes a unique divisibility property that can be intriguing and insightful when exploring number theory. It also presents a practical exercise for implementing digit manipulation and arithmetic operations in programming, thereby enhancing problem-solving skills in computational contexts.

Floyd's Triangle is constructed by sequentially filling rows with consecutive integers, starting from 1. Each row contains an incremental number of integers corresponding to its row number. For instance, the first row contains 1 number, the second row contains 2, and so on. This pattern is effectively demonstrated through nested loops: an outer loop for row numbers and an inner loop for printing numbers within each row, as portrayed in the document . The systematic arrangement forms a triangular pattern of integers, increasing incrementally by one per element.

A number is determined to be a spy number by calculating both the sum and the product of its digits, then comparing these two results. If they are equal, the number qualifies as a spy number. For example, with the number 1124, the sum of digits is 8 (1+1+2+4) and the product is also 8 (1x1x2x4). This concept highlights intricate properties of numbers derived purely from their digit components, encouraging deeper exploration into numerical representations and enhancing problem-solving skills through arithmetic and logic-based operations.

You might also like