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

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...
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...
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).
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....
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...
For the mspfr6989 write program #2 1(b) Write a program that will make LED1 blink 5...
For the mspfr6989 write program #2 1(b) Write a program that will make LED1 blink 5 times when S1 is pressed, and then stop. Program #2 – Using both S1 and S2 1 Write a program like 1(b) above, but the LED1 will blink until S2 is pressed. 2 Write a program that simulates a motor coming up to speed. When S1 is pressed, LED1 blinks at 50% duty cycle for 10 cycles (indicating a motor coming up to speed)....
Using the conditional assignment statements, write the verilog code for 16:1 Mux. Write the test bench...
Using the conditional assignment statements, write the verilog code for 16:1 Mux. Write the test bench for this module.
Write 2 short Java programs based on the description below. 1) Write a public Java class...
Write 2 short Java programs based on the description below. 1) Write a public Java class called WriteToFile that opens a file called words.dat which is empty. Your program should read a String array called words and write each word onto a new line in the file. Your method should include an appropriate throws clause and should be defined within a class called TextFileEditor. The string should contain the following words: {“the”, “quick”, “brown”, “fox”} 2) Write a public Java...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT