Aishiki Computer Programs
Aishiki Computer Programs
import java.util.*;
// Data members
private String name; // To store the customer's name
private String coach; // To store the type of coach
private long mobNo; // To store the customer's mobile number
private int amt; // To store the base ticket amount
private int totalAmt; // To store the updated total amount
/*
Variable Description:
1. name : String to store the name of the customer.
2. coach : String to store the type of coach the customer selects.
3. mobNo : long to store the mobile number of the customer.
4. amt : int to store the basic ticket amount based on coach type.
5. totalAmt : int to store the total amount after calculations (currently same as amt).
*/
QUESTION 2:
/* Name: Aishiki <your surname>
Class : 9 Section : <your section>
Roll number <roll no> */
import java.util.*;
switch (choice) {
case 1: // Check if a number is composite
System.out.print("Enter a number: ");
int number = sc.nextInt();
if (isComposite(number)) {
System.out.println(number + " is a composite number.");
} else {
System.out.println(number + " is not a composite number.");
}
break;
/*
Variable Description:
1. num : int, used to store the input number for operations.
2. choice : int, used to store the user's menu choice.
3. sum : int, used to store the sum of digits of a number.
4. digitNumber : int, the number input for digit sum calculation.
*/
}
QUESTION 3:
/* Name: Aishiki <your surname>
Class : 9 Section : <your section>
Roll number <roll no> */
import java.util.*;
switch (choice) {
case 1:
printLetterTriangle();
break;
case 2:
printMultiplicationTables();
break;
default:
System.out.println("Error: Invalid choice. Please select a valid option.");
}
/*
Variable Description:
1. row, col : char, used for printing rows and columns of the letter triangle pattern.
2. i, j : int, used for iterating through multiplication tables from 1 to 12 and 1 to 10 respectively.
3. choice : int, used to store the user's menu choice.
*/
}
QUESTION 4:
/* Name: Aishiki <your surname>
Class : 9 Section : <your section>
Roll number <roll no> */
import java.util.*;
if (n <= 0) {
System.out.println("Please enter a positive integer.");
} else {
// Print the Tribonacci series
System.out.println("The Tribonacci series up to " + n + " terms is:");
/*
Variable Description:
1. n : int, the number of terms in the Tribonacci series to be printed.
2. a : int, the first term of the series (initially 0).
3. b : int, the second term of the series (initially 0).
4. c : int, the third term of the series (initially 1).
5. next: int, stores the current term being calculated.
6. i : int, loop counter for iterating through terms after the first three.
*/
}
QUESTION 5:
/* Name: Aishiki <your surname>
Class : 9 Section : <your section>
Roll number <roll no> */
import java.util.*;
/*
Variable Description:
1. num : int, the number to check for being Pronic.
2. i : int, loop counter used to find consecutive integers whose product equals num.
*/
}
QUESTION 6:
/* Name: Aishiki <your surname>
Class : 9 Section : <your section>
Roll number <roll no> */
import java.util.*;
/*
Variable Description:
1. n : int, the number of terms in the series.
2. x : int, the base value for each term in the series.
3. sum : int, stores the cumulative sum of the series.
4. i : int, loop counter for iterating through the terms of the series.
*/
}
QUESTION 7:
/* Name: Aishiki <your surname>
Class : 9 Section : <your section>
Roll number <roll no> */
/*
Variable Description:
1. rows : int, the number of rows in the pattern.
2. i, j : int, loop counters for rows and stars in the pattern.
*/
}
QUESTION 8:
/* Name: Aishiki <your surname>
Class : 9 Section : <your section>
Roll number <roll no> */
import java.util.*;
System.out.println("Menu:");
System.out.println("1. Generate a triangle or inverted triangle");
System.out.println("2. Print the series: 2, 5, 10, 17, 26...");
System.out.print("Enter your choice: ");
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.print("Enter the number of terms (n): ");
int n = sc.nextInt();
System.out.println("Choose type of triangle: ");
System.out.println("1. Triangle");
System.out.println("2. Inverted Triangle");
System.out.print("Enter your choice: ");
int type = sc.nextInt();
if (type == 1) {
printTriangle(n);
} else if (type == 2) {
printInvertedTriangle(n);
} else {
System.out.println("Invalid choice for triangle type.");
}
break;
case 2:
System.out.print("Enter the number of terms (n): ");
int terms = sc.nextInt();
printSeries(terms);
break;
default:
System.out.println("Invalid choice. Please select a valid option.");
}
sc.close();
}
/*
Variable Description:
1. n : int, the number of terms for the triangle or series.
2. choice: int, the user's menu selection.
3. type : int, the type of triangle pattern (1 for normal, 2 for inverted).
4. term : int, stores the current term in the series.
*/
}
QUESTION 9:
/* Name: Aishiki <your surname>
Class : 9 Section : <your section>
Roll number <roll no> */
/*
Variable Description:
1. sum : double, used to store the cumulative sum of the series.
2. i : int, loop counter to represent the numerator of the current term.
*/
}
QUESTION 10:
/* Name: Aishiki <your surname>
Class : 9 Section : <your section>
Roll number <roll no> */
import java.util.*;
switch (choice) {
case 1: // Check for Spy Number
System.out.print("Enter a number: ");
int spyNum = sc.nextInt();
if (isSpyNumber(spyNum)) {
System.out.println(spyNum + " is a Spy Number.");
} else {
System.out.println(spyNum + " is not a Spy Number.");
}
break;
/*
Variable Description:
1. num : int, used for storing input number for operations.
2. sum, product : int, used for calculating the sum and product of digits.
3. originalNum : int, stores the original input number for divisibility checks.
4. choice : int, stores the user's menu selection.
*/
}