Question

In: Computer Science

This assignment is 2 programs demonstrating IF statements and Decisions. Program 1 Write a program that...

This assignment is 2 programs demonstrating IF statements and Decisions.

Program 1

Write a program that asks a user for a temperature for two storage containers for a spaceship filled with water and oxygen. The program should tell if either is ice and if either is boiling.

Numbers to use for your tests

The Freezing point of water is 32 and the boiling point is 212.

The Freezing point of oxygen is -362 and the boiling point is -306.

Program 2

People eating at a restaurant get to eat for free if they are younger than 10, pay full price if they are under 65, get a $3 discount if they are 65 or over. Write a program asking the user for an age of the next customer and the price of the food they ordered. Calculate how much to charge based on the price (set to 0, full price, or with a discount) along with a 15% tip. Then have the program show this amount to the user.

Examples:

What age is the person

5

What price is the meal

10

The charge for this person is 0

(a second program run)

What age is the person

70

What price is the meal

10

The charge for this person is 8.05

Solutions

Expert Solution

Program 1: Java language

import java.util.Scanner;

public class FreezeAndBoiling {

   public static void main(String[] args) {
       //Create a Scanner object for keyboard input.
   Scanner keyboard = new Scanner(System.in);

   System.out.print("Enter a temperature: ");
   double temperature = keyboard.nextDouble();
  
     
   //if statements
   if (temperature <= 32) {
       System.out.println("Water will freeze.");
}
   if (temperature >= 212) {
       System.out.println("Water will boil.");
}
  
   if (temperature <= -362) {
       System.out.println("Oxygen will freeze.");
}
   if (temperature >= -306) {
       System.out.println("Oxygen will boil.");
}
   }
}
Output:

Program 2: Java language

import java.util.Scanner;

public class CalculateBill {

   public static void main(String[] args) {
       //Create a Scanner object for keyboard input.
   Scanner keyboard = new Scanner(System.in);

   System.out.println("What age is the person");
   int age = keyboard.nextInt();
  
   System.out.println("What price is the meal");
   int mealPrice = keyboard.nextInt();
  
   double charge=0;
   int discount=3;
   // eat for free if they are younger than 10,
   if(age<=10) {
       System.out.println("The charge for this person is 0");
   }else if(age<65) {
       //calculating charge after applying tip 15%(15/100=0.15)
       charge = mealPrice + (mealPrice*0.15);
       System.out.println("The charge for this person is "+charge);
   }else if(age>=65){
       //calculating charge. discount if age >65
       charge = mealPrice - discount;
      
       //calculating charge after applying tip 15%(15/100=0.15)
       charge = charge + (charge*0.15);
       System.out.println("The charge for this person is "+charge);
   }
}
}
Output:


Related Solutions

This assignment is one program demonstrating IF statements and Decisions in C++ format. Program 2 People...
This assignment is one program demonstrating IF statements and Decisions in C++ format. Program 2 People eating at a restaurant get to eat for free if they are younger than 10, pay full price if they are under 65, get a $3 discount if they are 65 or over. Write a program asking the user for an age of the next customer and the price of the food they ordered. Calculate how much to charge based on the price (set...
Write in Python and as 2 seperate programs Write a program that allows the user to...
Write in Python and as 2 seperate programs Write a program that allows the user to enter the total rainfall for each of 12 months into a LIST. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts. Data: January 7.9 inches February 10.1 inches March 3.4 inches April 6.7 inches May 8.9 inches June 9.4 inches July 5.9 inches August 4.1 inches September...
Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1:...
Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1: User name Generator Write a program that prompts for and reads the user’s first and last name (separately). Then print a string composed of the first letter of the user’s first name, followed by the first five characters of the user’s last name, followed by a random number in the range 10 to 99. Assume that the last name is at least five letters...
Assignment 2 is on page 146, question 12. The assignment asks you to write a program...
Assignment 2 is on page 146, question 12. The assignment asks you to write a program to allow a user to enter a temperature in Celsius and convert it to Fahrenheit. Then display the new temperature on the screen. Consider using the fixed, showpoint, and setprecision stream manipulators with your output. (hint, probably points to what sort of numeric variables you should use) The formula to convert from C to F is in the book on page 146. For extra...
Write the programs in JavaScript: Write a program that reads a text file and outputs the...
Write the programs in JavaScript: Write a program that reads a text file and outputs the text file with line numbers at the beginning of each line.
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program that uses repetition (i.e. “loops”) and decision structures to solve a problem. 2. PROBLEM DEFINITION  Write a Python program that performs simple math operations. It will present the user with a menu and prompt the user for an option to be selected, such as: (1) addition (2) subtraction (3) multiplication (4) division (5) quit Please select an option (1 – 5) from the...
1 of the following government intervention programs: Supplemental Nutrition Assistance Program (SNAP) WRITE a 700- to...
1 of the following government intervention programs: Supplemental Nutrition Assistance Program (SNAP) WRITE a 700- to 1,050-word summary of your analysis. Identify the intervention and the market failure leading up to the intervention. Complete the following in your paper: Analyze the arguments for government intervention as opposed to arguments for market-based solutions.Hint:See the information about market failures. Examine who has been helped and who has been hurt by the selected government intervention. Examine externalities and unintended consequences of such intervention....
Write a program that reads a file (provided as attachment to this assignment) and write the...
Write a program that reads a file (provided as attachment to this assignment) and write the file to a different file with line numbers inserted at the beginning of each line. Such as Example File Input: This is a test Example File Output 1. This is a test. (Please comment and document your code and take your time no rush).
The goal of this assignment is to write five short Java/Pyhton programs to gain practice with...
The goal of this assignment is to write five short Java/Pyhton programs to gain practice with expressions, loops and conditionals. Boolean and integer variables and Conditionals. Write a program Ordered.java that reads in three integer command-line arguments, x, y, and z.   Define a boolean variable isOrdered whose value is true if the three values are either in strictly ascending order  (x < y < z) or in strictly descending order  (x > y > z), and false otherwise. Print out the variable isOrdered...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT