Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Translate the following code into python

import java.util.Scanner;

public class Main {

 

static Scanner scanner = new Scanner(System.in);

static final double PI = 3.14159;

public static void main(String[] args) {

// Display menu

System.out.println("Calculations");

System.out.println("1. Calculate area of a square");

System.out.println("2. Calculate area of a circle");

System.out.println("3. Display palindromes up to 1,000");

// Get input

System.out.print("Enter an option: ");

int option = scanner.nextInt();

if(option >= 1 && option <= 3) {

switch(option) {

case 1: {

System.out.println("\n**** Area of a square ****");

System.out.print("Enter width of square (cm): ");

int width = scanner.nextInt();

System.out.println("The area of a square of " + width + "cm = " + areaSquare(width) + "cm squared");

break;

}

case 2: {

System.out.println("\n**** Area of a circle ****");

System.out.print("Enter radius of circle (cm): ");

double radius = scanner.nextDouble();

System.out.println("The area of a square of " + radius + "cm = " + areaCircle(radius) + "cm squared");

break;

}

case 3: {

System.out.println("\n**** Palindromes ****");

for(int i = 0; i <= 1000; i++) {

if(isPalindrome(i)) {

System.out.println(i);

}

}

break;

}

}

} else {

System.out.println("Invalid option");

}

}

private static boolean isPalindrome(int num) {

String str = Integer.toString(num);

String reverse = "";

for(int i = str.length() - 1; i >= 0; i--) {

reverse += str.charAt(i);

}

return str.equals(reverse);

}

 

private static int areaSquare(int width) {

return width * width;

}

 

private static double areaCircle(double radius) {

return PI * (radius * radius);

}

}

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education