Sandeep is tasked with creating a credit score calculator program that assesses an individual's creditworthiness based on different criteria. The program should provide credit scores in three categories: Credit Score, Debt Score, and Income Score.
Credit Score Calculation
Debt Score Calculation
Income Score Calculation
Help Sandeep to complete the task using 'switch-case' statements.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int choice = scanner.nextInt();
switch (choice) {
case 1:
int latePayments = scanner.nextInt();
int creditScore;
switch (latePayments) {
case 0: creditScore = 800; break;
case 1: creditScore = 750; break;
case 2: creditScore = 700; break;
case 3: creditScore = 650; break;
case 4: creditScore = 600; break;
case 5: creditScore = 550; break;
default: creditScore = 0; break;
}
System.out.println("Credit Score: " + creditScore);
break;
case 2:
double debtToIncome = scanner.nextDouble();
String debtScore;
if (debtToIncome <= 30) {
debtScore = "Good";
} else if (debtToIncome <= 50) {
debtScore = "Average";
} else {
debtScore = "Poor";
}
System.out.println("Debt Score: " + debtScore);
break;
case 3:
double annualIncome = scanner.nextDouble();
String incomeScore;
if (annualIncome >= 50000) {
incomeScore = "Good";
} else if (annualIncome >= 30000) {
incomeScore = "Average";
} else {
incomeScore = "Poor";
}
System.out.println("Income Score: " + incomeScore);
break;
}
scanner.close();
}
Sophie is a meteorologist, and she needs a program to convert temperatures from Fahrenheit to Celsius. However, she also wants the program to warn her when the entered temperature is outside the human-survivable temperature range. The program should take a temperature in Fahrenheit as input, validate whether it's within the safe range, and convert it to Celsius if it is.
Formula: celsius = (fahrenheit - 32) * 5/9
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double fahrenheit = scanner.nextDouble();
if (fahrenheit >= -100 && fahrenheit <= 150) {
double celsius = (fahrenheit - 32) * 5 / 9;
System.out.printf("Temperature in Celsius: %.2f C\n", celsius);
} else {
System.out.println("Temperature outside the human-survivable range");
}
scanner.close();
}
Maria is building a program to classify triangles based on side lengths. The program should take three integer inputs and identify if the triangle is equilateral, isosceles, scalene, or right-angled. Help Maria create this classification program.
Note: - Equilateral - all sides equal - Isosceles - two sides equal - Scalene - all sides different - Right-angled - The square of one side equals the sum of the squares of the other two sides.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
if (a == b && b == c) {
System.out.println("The triangle is equilateral");
} else if (a == b || b == c || a == c) {
System.out.println("The triangle is isosceles");
} else {
System.out.println("The triangle is scalene");
}
if (a * a + b * b == c * c || b * b + c * c == a * a || a * a + c * c == b * b) {
System.out.println("The triangle is also right-angled");
}
scanner.close();
}
Brian is developing a program that requires analyzing numbers. He needs to determine whether a given number is positive, negative, or zero.
Help Brian create the program.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int number = scanner.nextInt();
if (number > 0) {
System.out.println("Positive");
} else if (number < 0) {
System.out.println("Negative");
} else {
System.out.println("Zero");
}
scanner.close();
}
Maya is given a two-digit number and needs to find the sum of its digits. She wants to know if the sum is less than 10 or not. Your task is to write a program to calculate and print the sum of the digits and provide a message based on the result.
n
.n
is not a two-digit number, print "Not a valid two-digit number." public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
if (n >= 10 && n <= 99) {
int sum = (n / 10) + (n % 10);
System.out.println("Digit Sum: " + sum);
if (sum < 10) {
System.out.println("The sum of the digits is less than 10.");
} else {
System.out.println("The sum of the digits is not less than 10.");
}
} else {
System.out.println("Not a valid two-digit number.");
}
scanner.close();
}
Sarah, a student studying coordinate geometry, needs a program to calculate the slope, distance, and midpoint of line segments. She wants to understand how to work with Cartesian coordinates. Write a program to allow her to choose an operation and calculate the desired property based on two points.
Formulas:
- slope = (y2 - y1) / (x2 - x1)
- distance = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
- midpointX = (x1 + x2) / 2
- midpointY = (y1 + y2) / 2
x1, y1, x2, y2
representing the coordinates.(x, y)
. public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int choice = scanner.nextInt();
double x1 = scanner.nextDouble();
double y1 = scanner.nextDouble();
double x2 = scanner.nextDouble();
double y2 = scanner.nextDouble();
switch (choice) {
case 1:
if (x2 != x1) {
double slope = (y2 - y1) / (x2 - x1);
System.out.println("Slope: " + slope);
} else {
System.out.println("Slope: Undefined");
}
break;
case 2:
double distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
System.out.printf("Distance: %.2f\n", distance);
break;
case 3:
double midpointX = (x1 + x2) / 2;
double midpointY = (y1 + y2) / 2;
System.out.printf("Midpoint: (%.1f, %.1f)\n", midpointX, midpointY);
break;
default:
System.out.println("Invalid choice. Please select a valid option.");
break;
}
scanner.close();
}