Carlos is managing TechNova Electronics' inventory system. She is given a task to create a program that reads the device name, model number, and status and displays the formatted device information.
Since she is new to programming, can you assist Carlos in this task?
Input format : The first line of input consists of a string, representing the device name.
The second line consists of a string, representing the status.
The third line consists of an integer, representing the model number.
Output format : The first line of output prints "Device Name: " followed by the device name.
The second line prints "Status: " followed by the status.
The third line prints "Model Number: " followed by the model number.
```java public static void main(String[] args) { Scanner scanner = new Scanner(System.in);
String deviceName = scanner.nextLine();
String status = scanner.nextLine();
int modelNumber = scanner.nextInt();
System.out.println("Device Name: " + deviceName);
System.out.println("Status: " + status);
System.out.println("Model Number: " + modelNumber);
scanner.close();
}
---
2. Problem Statement
Maria, a software developer, is working on a project to perform arithmetic operations on four integers. She wants to create a simple program that takes four integers as input in which all the inputs are either positive or negative integers and calculates the result based on the formula: (a + b - c * d / a) % b. However, she has a specific requirement for the output format.
Input format :
The input consists of four lines:
The first line contains an integer a which can be either a positive or negative integer.
The second line contains an integer b which can be either a positive or negative integer.
The third line contains an integer c which can be either a positive or negative integer.
The fourth line contains an integer d which can be either a positive or negative integer.
Output format :
The output displays the result of the arithmetic operation in the following format: "(a + b - c * d / a) % b = [result]"
Here, [result] should be replaced with the calculated value(integer).
## Solution
```java
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
int d = scanner.nextInt();
int result = (a + b - c * d / a) % b;
System.out.println("(a + b - c * d / a) % b = " + result);
scanner.close();
}
Aishu wants to develop a program to calculate the total viewing time for a movie marathon of the Deadpool series based on the number of movies and the frequency of breaks.
She is provided with the following information:
Each movie in the series has a fixed duration of 45 minutes. After watching a certain number of movies, there is a break of 15 minutes.
Assist Aishu in creating a program that accepts input for the total number of movies in the series and the number of movies watched before a break. Calculate and output the total viewing time required to watch the entire series, including the breaks. Use the conditional operator for the same.
Input format : The first line of input consists of an integer n, representing the total number of movies in the series.
The second line consists of an integer k, representing the number of movies watched before a break.
Output format : The output displays an integer representing the total viewing time required to watch the entire series, including the breaks, in minutes.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
int totalViewingTime = n * 45 + ((n - 1) / k) * 15;
System.out.println(totalViewingTime + " minutes");
scanner.close();
}
Alex needs a program to determine which of the two points is closer to the origin and to identify the orientation of the line segment connecting these two points. The orientation is determined based on the coordinates of the two points.
The program should:
Calculate the distance of each point from the origin (0, 0). Determine which point is closer to the origin. Identify the orientation of the line segment between the two points based on their coordinates: Vertical: If the x-coordinates of both points are the same. Horizontal: If the y-coordinates of both points are the same. Oblique: If neither the x-coordinates nor the y-coordinates of the two points are the same.
Assist Alex in the program.
Formula:
distance1 = Math.sqrt(x1 * x1 + y1 * y1)
distance2 = Math.sqrt(x2 * x2 + y2 * y2)
Input format : The input consists of four integers representing the coordinates of the two points:
x1 and y1 for the first point. x2 and y2 for the second point, separated by a space Output format : The first line of output prints a double value, representing the distance of the closer point to the origin, formatted to one decimal place.
The second line prints the orientation of the line segment connecting the two points.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int x1 = scanner.nextInt();
int y1 = scanner.nextInt();
int x2 = scanner.nextInt();
int y2 = scanner.nextInt();
double distance1 = Math.sqrt(x1 * x1 + y1 * y1);
double distance2 = Math.sqrt(x2 * x2 + y2 * y2);
double closerDistance = Math.min(distance1, distance2);
System.out.printf("Closer Distance: %.1f\n", closerDistance);
if (x1 == x2) {
System.out.println("Orientation: Vertical");
} else if (y1 == y2) {
System.out.println("Orientation: Horizontal");
} else {
System.out.println("Orientation: Oblique");
}
scanner.close();
}
A prominent real estate agency, 'EstatePro', is streamlining its customer service by automating lease calculations and payment method suggestions. As a software developer, your mission is to create a program that will calculate the total cost of leasing a property based on the monthly rent and the duration of the lease in months.
Additionally, provide payment method suggestions to the customers, using a 'switch-case' statement.
If the total cost is less than or equal to 1000, suggest payment by cash or check. If the total cost is between 1000 and 5000 (inclusive), suggest payment by credit card. If the total amount is over 5000, suggest payment by bank transfer. Input format : The first line of input consists of an integer, representing the monthly rent.
The second line consists of an integer, representing the lease duration.
Output format : The first line of output prints "Total Cost: " followed by an integer, representing the total cost of the lease.
The second line prints "Payment Method Suggestion: " followed by a string representing the payment method suggestion.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int monthlyRent = scanner.nextInt();
int leaseDuration = scanner.nextInt();
int totalCost = monthlyRent * leaseDuration;
System.out.println("Total Cost: " + totalCost);
int range;
if (totalCost <= 1000) {
range = 1;
} else if (totalCost <= 5000) {
range = 2;
} else {
range = 3;
}
String paymentSuggestion;
switch (range) {
case 1:
paymentSuggestion = "Payment by cash or check is recommended.";
break;
case 2:
paymentSuggestion = "Payment by credit card is recommended.";
break;
case 3:
paymentSuggestion = "Payment by bank transfer is recommended.";
break;
default:
paymentSuggestion = "Invalid range.";
}
System.out.println("Payment Method Suggestion: " + paymentSuggestion);
scanner.close();
}