Question

In: Computer Science

JAVA script! You will write a program that will input the nationalities of your favorite types...

JAVA script!

You will write a program that will input the nationalities of your favorite types of food, examples, and prices of some of your favorite food. You will save a type of food, two examples of that type of food, the price of each of those two examples, and a total price of both together. You must input your own types, examples, and prices, but check a sample run below. You must use the concepts and statements that we have covered so far this semester. Use a loop that loops two times using a counter. Inside the loop, first ask the user to input the nationality of their favorite foods (ex. German, Italian, etc.). The user will now input an example of that type of food and the cost of that food. The user will now input another example of that type of food and the cost of that food. Add the two costs to a total amount variable. Now output the nationality of the type of food and the total amount of the two types of food rounded to two decimal places. Then, ask the user if they would like to list their choices, by answering either y/n or 1/2. If they say y or 1 for yes, print the two examples of that type of food. Hint: When running your program, keep track of the enters in the memory buffer. Whenever an input is skipped over, clear the enter from the input memory buffer. Whenever the program wants an extra input, do not clear the input memory buffer.

Solutions

Expert Solution

<!DOCTYPE html>
<html>
<head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>My favorite Food</title>
        <link rel="stylesheet" href="">
</head>
<body>
        <div class="container">
                <p id="nation"></p>
                <p id="food"></p>
                <p id="totalprice"></p>
        </div>
</body>
<script type="text/javascript">
        var fvrfood = [];
        
for (var i=0;i<2;i++){
        var nationIN = prompt("Please enter food nationality");
        var food = prompt("Please enter your favorite food ", "food name");
        var price = prompt("Please enter food price","food price");
        


                fvrfood.push((nationIN),(food),Number(price));
        }
        var choice = prompt("Are you want print your data enter y/n")
        
 if(choice == "y"){
    var print = fvrfood.values();
for (var elements of print) { 
  console.log(elements);
} 
}
else{
        console.log("end");
}
                
        
        




</script>
</html>

Related Solutions

In the second task, you will write a Java program that validates an input to see...
In the second task, you will write a Java program that validates an input to see whether it matches a specified pattern. You will have to read a bit about regular expressions for this Lab. 1. Prompt the user to enter the email address. 2. Read the user input as a String. 3. A regular expression that specifies the pattern for an email address is given by “[a-zA-Z0- 9.]++@[a-zA-Z]++.(com|ca|biz)”. Use this as the input to the matches method in the...
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Write a java script function that accepts integer array as input, and display a new array...
Write a java script function that accepts integer array as input, and display a new array by performing fol lowing modifications, • The values in odd index positions must be incremented by 1 • The values in even index positions must be decremented by 1. • Assume the array index starts from 0. Input 1: arr = [1,2,3,4] Output 1: arr = [0,3,2,5 it done html and javascript and plz do it in simple way
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles, and the class of journey (1,2, or 3, for first, second, and third class respectively), for a train journey. The program should then calculate and display the fare of journey based on the following criteria: Note: Use Switch...case and if...else construct First (1) Class Second (1) Class Third (3) Class First 100 mile $ 3 per mile $ 2 per mile $ 1.50...
Write a program in Java that will take as input two sets A and B, and...
Write a program in Java that will take as input two sets A and B, and returns a list of all functions from A to B.
Write a java program that read a line of input as a sentence and display: ...
Write a java program that read a line of input as a sentence and display:  Only the uppercase letters in the sentence.  The sentence, with all lowercase vowels (i.e. “a”, “e”, “i”, “o”, and “u”) replaced by a strike symbol “*”.
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
java program: Input and output the following details. Your program can only receive the correct input....
java program: Input and output the following details. Your program can only receive the correct input. (For example: a notification will be given if you not enter Char data type for Name) Name: Ali bin Ahmad Occupation: Technician Age: 30 Hometown: Negeri Sembilan Years of Service: 12 Gender: Male
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT