












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This is a document that will serve as your guide to create a code that uses all three of the programming languages named java, python & c++
Typology: Study Guides, Projects, Research
1 / 20
This page cannot be seen from the preview
Don't miss anything!













1.Astronomy Helper Create an application that displays the following menu: Select a Planet
_1. Mercury
import java.util.Scanner; public class Main { public static void main(String[] args) { int menuSelection = 0; do { // Display the menu and get the user's selection menuSelection = displayMenu(); // Display the information for the user's selection switch (menuSelection) { case 1: printPlanet("MERCURY", "57.9", "3.31 x 10^23", "-173 to 430"); break; case 2: printPlanet("VENUS", "108.2", "4.87 x 10^24", "472"); break; case 3: printPlanet("EARTH", "149.6", "5.967 x 10^24", "-50 to 50"); break; case 4: printPlanet("MARS", "227.9", "0.6424 x 10^24", "-140 to 20"); break;
while (menuSelection != 5); } // Call the displayMenu method to display the menu options and get the // user's selection public static int displayMenu() { System.out.println("Please select a planet to view details about it's: "); System.out.println("average distance from the sun, mass, and surface temperature."); System.out.println("_________________________________________________________"); System.out.println("1. Mercury"); System.out.println("2. Venus"); System.out.println("3. Earth"); System.out.println("4. Mars"); System.out.println("5. EXIT the program"); System.out.println("Enter your selection: "); Scanner keyboard = new Scanner(System.in); int menuSelection = keyboard.nextInt(); // Validate the menu selection while (menuSelection < 1 || menuSelection > 5) { System.out.print("This is an invalid selection."); System.out.print("Enter a selection from 1-5: "); menuSelection = keyboard.nextInt(); } return menuSelection; } public static void printPlanet(String planet, String distanceToSun, String mass, String degrees) {
condition = menuSelection != 5 while (menuSelection != 5): def displayMenu(): print("Please select a planet to view details about it's: ") print("average distance from the sun, mass, and surface temperature.") print("_________________________________________________________") print("1. Mercury") print("2. Venus") print("3. Earth") print("4. Mars") print("5. EXIT the program") print("Enter your selection: ") while menuSelection < 1 or menuSelection > 5: print("This is an invalid selection.", end = '') print("Enter a selection from 1-5: ", end = '') def printPlanet(planet, distanceToSun, mass, degrees): print("\t\t\t " + planet) print("_________________________________________________________") print("Average Distance from the sun: " + distanceToSun + " million kiometers") print("Mass: " + mass + " kg") print("Surface Temperature: " + degrees + " degrees Celsius") print("_________________________________________________________") C++
#include
return menuSelection; } static void printPlanet(std::string planet, std::string distanceToSun, std::string mass, std::string degrees) { std::cout << "\t\t\t " + planet << std::endl; std::cout << "_________________________________________________________" << std::endl; std::cout << "Average Distance from the sun: " + distanceToSun + " million kiometers" << std::endl; std::cout << "Mass: " + mass + " kg" << std::endl; std::cout << "Surface Temperature: " + degrees + " degrees Celsius" << std::endl; std::cout << "_________________________________________________________" << std::endl; } }; int main(int argc, char **argv){ std::vector<std::string> parameter(argv + 1, argv + argc); Main::main(parameter); return 0; };
import java.util.Scanner; public class Main { public static void main(String[] args) { int passwordLength=8, upChars=0, lowChars=0; int special=0, digits=0; char ch; Scanner s = new Scanner(System.in); System.out.println("----Direction to Create a Password----"); System.out.println("1. The Password must be at least 8 characters long."); System.out.println("2. The Password must contain at least one uppercase character."); System.out.println("3. The Password must contain at least one lowercase character."); System.out.println("4. The Password must contain at least one digit (0-9)."); System.out.println("5. The Password must contain at least one special characters."); System.out.println("6. The Password must not contain < or >."); System.out.print("\nCreate a Password: "); String password = s.nextLine(); int total = password.length(); if(total<passwordLength) { System.out.println("\nThe Password's Length has to be of 8 characters or more."); return;
else { System.out.println("\nThe Strength of Password is Medium."); } System.out.println("\n----The Password Contains----"); System.out.println("UpperCase Character: " +upChars); System.out.println("LowerCase Character: " +lowChars); System.out.println("Digit: " +digits); System.out.println("Special Character: " +special); } else { if(upChars==0) System.out.println("\nThe Password must contain at least one uppercase character."); if(lowChars==0) System.out.println("\nThe Password must contain at least one lowercase character."); if(digits==0) System.out.println("\nThe Password must contain at least one digit."); if(special==0) System.out.println("\nThe Password must contain at least one special character."); } } } PYTHON import re v=input("Enter the password:") if(len(v)>=8): if(bool(re.match('((?=.\d)(?=.[a-z])(?=.[A-Z])(?=.[!@#$%^&*]).{8,30})',v))==True):
print("The password is strong") elif(bool(re.match('((\d)([a-z])([A-Z])([!@#$%^&]*).{8,30})',v))==True): print("The password is weak") else: print("You have entered an invalid password.") C++ #include
return (base * power(base, powerRaised - 1)); } else { return 1; } } } PYTHON def power(base,exp): if(exp==1): return(base) if(exp!=1): return(base*power(base,exp-1)) base=int(input("Enter base: ")) exp=int(input("Enter exponential value: ")) print("Result:",power(base,exp)) C++ #include
cin >> base; cout << "Enter power number(positive integer): "; cin >> powerRaised; result = calculatePower(base, powerRaised); cout << base << "^" << powerRaised << " = " << result; return 0; } int calculatePower(int base, int powerRaised) { if (powerRaised != 0) return (base*calculatePower(base, powerRaised-1)); else return 1; }