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

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...
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.
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
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
a). Write a program that asks the user to enter an integer N and prints two...
a). Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than...
2. Write a program C++ that asks the user for a number (not necessary to force...
2. Write a program C++ that asks the user for a number (not necessary to force any particular requirements). Write a function with the following signature: double square(double x) that returns the square of the user's number (x * x). 3. Write a C++ program that asks the user for an integer. Write a function that returns 1 of the number is even, and 0 if the number is odd. Use this function signature: int isEven(int x). 4. Write a...
Write a MIPS program that asks the user for 2 numbers. Output the sum of the...
Write a MIPS program that asks the user for 2 numbers. Output the sum of the 2 numbers. The difference between the 2 numbers (num1-num2) and (num2-num1) The value that is 305 more than the 1st number. The value that is 305 less than the 2nd number
2. Write a program that asks for hexadecimal number and converts it to decimal. Then change...
2. Write a program that asks for hexadecimal number and converts it to decimal. Then change it to convert an octal number to decimal in perl language.
Write a C program that asks the user to enter any two integernumbers, and each...
Write a C program that asks the user to enter any two integer numbers, and each number consists of four-digits. Your program should check whether the numbers are four digits or not and in case they are not a four digit number, the program should print a message and exit, otherwise it should do the following:Print a menu as follows:Select what you want to do with the number 1-3:1- Print Greatest Common Divisor (GCD) of the two numbers.2- Print sum...
• Write a C++ program that asks the user to input two integer values, then calls...
• Write a C++ program that asks the user to input two integer values, then calls a void function "swap" to swap the values for the first and second variable. • As we mentioned before, in order to swap the valors of two variables, one can use the following: temp= variable1; variable1 = variable2; variable2 = temp; • Display the two variables before you call swap and after you call that function. Comment in code would be greatly appreciated to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT