In: Computer Science
in.java
Two companies donated money on two occasions. Write a program that:
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
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.