Question

In: Computer Science

in.java Two companies donated money on two occasions. Write a program that: asks for 2 names...

in.java

Two companies donated money on two occasions. Write a program that:

  • asks for 2 names of companies
  • aks how much each of the given companies donated for Christmas.
  • aks how much each of the given companies donated for school support
  • prints the total donations for Christmas
  • prints the total donations for school support
  • prints which one of 2 companies donated more money in general.

For clarity, in the sample runs below, the user input is shown in blue. The black text is printed by the program.
Notice that the company name (entered by the user) shows in the following questions. For example see: "AC4Ever donated: ", "RockOn donated: "

---- Sample run 1
Enter the first company: AC4Ever 
Enter the second company: RockOn 
Enter how much each company donated for Christmas gifts:
AC4Ever donated: 2000
RockOn donated: 1700
Enter how much each company donated for school support:
AC4Ever donated: 3000
RockOn donated: 2500
Total Christmas donations: 3700
Total school support donations: 5500
The company that donated the most is: AC4Ever
Bye

Solutions

Expert Solution

import java.util.Scanner;

public class Donations {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the first company: ");

String company1 = sc.nextLine();

System.out.print("Enter the second company: ");

String company2 = sc.nextLine();

System.out.println("Enter how much each company donated for Christmas gifts: ");

System.out.print(company1 + " donated: ");

int d1 = sc.nextInt();

System.out.print(company2 + " donated: ");

int d2 = sc.nextInt();

System.out.println("Enter how much each company donated for school support: ");

System.out.print(company1 + " donated: ");

int d11 = sc.nextInt();

System.out.print(company2 + " donated: ");

int d22 = sc.nextInt();

d1 = d1 + d2 ;

d11 = d11 + d22;

System.out.println("Total Christmas donations: "+ d1);

System.out.println("Total school support donations: "+ d11);

if( d1 + d11 > d2 + d22)

System.out.println("The company that donated the most is: "+ company1 );

else

System.out.println("The company that donated the most is: "+ company1 );

System.out.println("Bye");

}

}

============================================================

SEE OUTPUT

Thanks, PLEASE COMMENT if there is any concern.

Thanks, PLEASE COMMENT if there is any concern.


Related Solutions

In.java Write down a program that asks the user for their full name given in the...
In.java Write down a program that asks the user for their full name given in the format first last. The program will do the necessary processing and print the name in a table with 3 columns: Last, First, Initials. Requirements/Specifications... Your program run must be identical with the one shown as an example (both in how it reads the input and it on what it prints). The table must have the top and bottom lines as shown. The columns for...
In.java Write a program that repeatedly asks the user to enter their password until they enter...
In.java Write a program that repeatedly asks the user to enter their password until they enter the correct one. However, after 5 failed attempts, the program "locks out" the user. We will show that with an error message. Assume the password is HOC2141 (case sensitive). Note that there is a special case that is not shown below. To identify it, think of all possible scenarios of input for this program. ----------- Sample run 1: Enter your password: Blake Wrong Enter...
Create a program that asks the user for the names of two car dealerships and the...
Create a program that asks the user for the names of two car dealerships and the # of cars sold in each one. Then output that data in two columns as shown below. The "Store location" column has a width of 25, while the "Cars sold" column has a width of 9. Also, notice the alignment of the second column. The program should end with the "Press Enter to end this program" prompt. OUTPUT Enter the location for the first...
Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
in.java Write a program that reads an integer from the user and prints a rectangle of...
in.java Write a program that reads an integer from the user and prints a rectangle of starts of width 5 3 and height N. Sample run 1: Enter N: 5 *** *** *** *** *** Bye Sample run 2: Enter N: 8 *** *** *** *** *** *** *** *** Bye Sample run 3: Enter N: 2 *** *** Bye Sample run 4: Enter N: -2 Bye
JAVA Write a program that will compare two names. The program prompts the user to enter...
JAVA Write a program that will compare two names. The program prompts the user to enter two names for a comparison. If the names are same, the program states that. If the names are different, the program converts both names to UPPERCASE, and compares then again. If they are equal, the programs displays a message stating that names are equal if CASE is ignored. Otherwise, the program prints names with a message that names are not equal.  Check also if there...
In.java In this program write a method called upDown that takes three integers as arguments and...
In.java In this program write a method called upDown that takes three integers as arguments and returns one of these 3 strings: "increasing" if they are in strictly increasing order (note that 3,3,4 - are not strictly increasing), "decreasing" if they are in strictly decreasing order. "none" otherwise. I recommend you use a complex condition to check for this (that is, have a single if statement with one big question). In the main method do the following: read three integers...
11. First and Last Design a program that asks the user for a series of names...
11. First and Last Design a program that asks the user for a series of names (in no particular order). After the final person's name has been entered, the program should display the name that is first alphabetically and the name that is last alphabetically. For example, if the user enters the names Kristin, Joel, Adam, Beth, Zeb, and Chris, the program would display Adam and Zeb. #Sentinel value is DONE SENTINEL = "DONE" ls = [] prompt = "Enter...
Write a program that asks the user to type in two integer values. Test these two...
Write a program that asks the user to type in two integer values. Test these two numbers to determine whether the first is evenly divisible by the second and then display the appropriate message to the terminal. Objective C
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT