Question

In: Computer Science

1- Write a Java program called ArabicMonth that randomly generates an integer between 1 and 12...

1- Write a Java program called ArabicMonth that randomly generates an integer between 1 and 12 and displays the month name Jan, Feb, …, December for
the number 1, 2, …, 12, accordingly..

Sample Run:
9 Oct











2- Write a program that prompts the user to enter the exchange rate from currency in U.S. dollars to Saudi Riyals. Prompt the user to enter 0 to convert from U.S. dollars to Saudi Riyals and 1 to convert from Saudi Riyal and U.S. dollars. Prompt the user to enter the amount in U.S. dollars or Saudi Riyal to convert it to Saudi Riyal or U.S. dollars, respectively.

Here are the sample runs:
Enter the exchange rate from dollars to SR: 3.75
Enter 0 to convert dollars to SR and 1 vice versa: 0
Enter the dollar amount: 100
$100.0 is 375.0 SR

Solutions

Expert Solution

Please find below code and Don't forget to give a Like.

Refer screenshot for output.

a)

import java.lang.Math;
public class Main
{
   public static void main(String[] args) {
   String []arr={"jan","feb","march","april","may","june","july","august","september","october","november","december"};
   int min=1,max=12;
   int a =(int)(Math.random()*(max-min+1)+min);
   for(int i=1;i<=arr.length;i++){
   if(i==a){
   System.out.print(a+" "+arr[i-1]);
   }
   }
  
  
}
}

b)

import java.util.Scanner;
public class Main
{
   public static void main(String[] args) {
   double conversion=0.0;
   Scanner input=new Scanner(System.in);
   System.out.print("Enter the exchange rate from dollars to SR:");
   double price=input.nextDouble();
   System.out.print("Enter 0 to convert dollars to SR and 1 vice versa:");
   int choice=input.nextInt();
   if(choice==0){
   System.out.print("Enter dollar amount:");
   double d_amount=input.nextDouble();
   conversion=price*d_amount;
   System.out.print("$"+d_amount+" is "+conversion+" SR");
   }
   if(choice==1){
   System.out.print("Enter SR amount:");
   double s_amount=input.nextDouble();
   price=1/price;
   conversion=price*s_amount;
   System.out.print(s_amount+" SR "+" is $"+conversion);
   }
}
}


Related Solutions

Write a program in java which randomly generates two integer number n1 and n2 (suppose the...
Write a program in java which randomly generates two integer number n1 and n2 (suppose the range for each integer is [1, 100]), then asks the user what is the value of n1*n2, if the user’s answer is correct, call method printGoodComment to print out something nice, otherwise, call printBadComment to print out something “mean”. The method signatures are:                   public static void printGoodComment() and                   public static void printBadComment() in your printGoodComment method, it will randomly print one sentence from the...
Write a program in java which randomly generates two integer number n1 and n2 (suppose the...
Write a program in java which randomly generates two integer number n1 and n2 (suppose the range for each integer is [1, 100]), then asks the user what is the value of n1*n2, if the user’s answer is correct, call method printGoodComment to print out something nice, otherwise, call printBadComment to print out something “mean”. The method signatures are:                   public static void printGoodComment() and                   public static void printBadComment() in your printGoodComment method, it will randomly print one sentence from the...
C++ code: Write a program that randomly generates an integer between 0 and 100, inclusive. The...
C++ code: Write a program that randomly generates an integer between 0 and 100, inclusive. The program prompts the user to enter a number continuously until the number matches the randomly generated number. For each user input, the program tells the user whether the input is too low or too high, so the user can choose the next input intelligently. Here is a sample run:
Write a Java program with comments that randomly generates an array of 500,000 integers between 0...
Write a Java program with comments that randomly generates an array of 500,000 integers between 0 and 499,999, and then prompts the user for a search key value. Estimate the execution time of invoking the linearSearch method in Listing A below. Sort the array and estimate the execution time of invoking the binarySearch method in Listing B below. You can use the following code template to obtain the execution time: long startTime = System.currentTimeMillis(); perform the task; long endTime =...
Write a C++ program that randomly generates N integer numbers (such that N is entered by...
Write a C++ program that randomly generates N integer numbers (such that N is entered by the user) and then stores them to a text file (myNumbers.txt) sorted in increasing (non-decreasing) order. Again, please notice that the size of the data (N) is known during the run time, not the compile-time (needs to be entered by the user after running the program).
we saw a C program called GuessNumber.c that generates a random integer between 1 and 1000...
we saw a C program called GuessNumber.c that generates a random integer between 1 and 1000 and asks the user to guess that number. Modify the program so that at the end of each round, it also prints the number of guesses made by the user to reach the answer as well as the best score so far, i.e., the minimum number of guesses used in any round since the program was started. The source code of the original version...
Write a program that repeatedly generates a random integer in the range [1, 100], one integer...
Write a program that repeatedly generates a random integer in the range [1, 100], one integer at a time, and displays the generated numbers on the screen according to the following rules: If the second number generated is greater than the first number, they are displayed on the screen in the order of their input and while the next random number generated is greater than the previous one, the random number is displayed on the screen and the program continues....
Write a program that repeatedly generates a random integer in the range [1, 100], one integer...
Write a program that repeatedly generates a random integer in the range [1, 100], one integer at a time, and displays the generated numbers on the screen according to the following rules: If the second number generated is greater than the first number, they are displayed on the screen in the order of their input and while the next random number generated is greater than the previous one, the random number is displayed on the screen and the program continues....
Write a program that repeatedly generates a random integer in the range [1, 100], one integer...
Write a program that repeatedly generates a random integer in the range [1, 100], one integer at a time, and displays the generated numbers on the screen according to the following rules: If the second number generated is greater than the first number, they are displayed on the screen in the order of their input and while the next random number generated is greater than the previous one, the random number is displayed on the screen and the program continues....
Write a java program which can randomly generate a permutation of the integer {1, 2, 3,...
Write a java program which can randomly generate a permutation of the integer {1, 2, 3, ..., 48,49,50}. Use the most efficient sorting algorithm to sort the list in an acceding order.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT