Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. import java.util.Scanner;//use this if program needs user to input info
  2.  
  3. public class fundraisersWarray
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner inputS=new Scanner(System.in);//needed for user input for text types
  8. Scanner inputN=new Scanner(System.in);//needed for user input for numeric types
  9. String nameT, searchValue;
  10. String[] names;
  11. double[] bonus;
  12. double[] amtraise;
  13. int studentNumb,numbOfBox,response,index=-1,totalBoxes=0, stBoxes;
  14. double totalEarn=0,totalBonus=0;
  15.  
  16. System.out.println ("Who's homeroom is this?");
  17. nameT=inputS.nextLine();
  18. System.out.println ("How many students are there in "+nameT+" 's class?");
  19. studentNumb=inputN.nextInt();
  20.  
  21. names = new String[studentNumb];
  22. bonus = new double[studentNumb];
  23. amtraise = new double[studentNumb];
  24.  
  25. for(int i=0; i<studentNumb;i++)
  26. {
  27. System.out.println("");
  28. System.out.println("what is the name of Student "+(i+1)+"?");
  29. names[i]=inputS.nextLine();
  30. System.out.println("");
  31. System.out.println("what is the number of boxes "+names[i]+" manage to sell?");
  32. numbOfBox=inputN.nextInt();
  33. System.out.println("");
  34.  
  35. if (50<numbOfBox)
  36. {
  37. bonus[i]=10;
  38. }
  39. else
  40. {
  41. bonus[i]=0;
  42. }
  43. amtraise[i]=1.25*numbOfBox+bonus[i];
  44. totalBonus=totalBonus+bonus[i];
  45. totalEarn=totalEarn+amtraise[i];
  46. totalBoxes=totalBoxes+numbOfBox;
  47. }
  48. while (true)
  49. {
  50. System.out.println("");
  51. System.out.println ("Fundraiser View for "+nameT+"'s class");
  52. System.out.println ("1. View 1 student");
  53. System.out.println ("2. View all students");
  54. System.out.println ("3. exit");
  55. response=inputN.nextInt();
  56.  
  57. if (response==1)
  58. { System.out.println ("Which student would you like to check?");
  59. searchValue=inputS.nextLine();
  60.  
  61. for (int i=0;i < names.length;i++)
  62. {
  63. if (names[i].equalsIgnoreCase(searchValue)) // if current array value is the integer being searched for...
  64. {
  65. index=i;
  66. break;
  67. }
  68. else
  69. {
  70. System.out.println(searchValue +" not found");
  71. break;
  72. }
  73. }
  74. if(index!=-1)
  75. {
  76. stBoxes= (int)((amtraise[index]-bonus[index])/1.25);
  77. System.out.println("\nSingle Student Fundraiser Summary");
  78. System.out.println("---------------------------------------------");
  79. System.out.println(String.format("%-17s","Name:")+String.format("%-10s","Boxes:")+String.format("%-10s","Bonus:")+String.format("%-8s","Earned:"));
  80. System.out.println("---------------------------------------------");
  81. System.out.println(String.format("%-18s",names[index])+String.format("%-6s",stBoxes)+" $"+String.format("%4.0f",bonus[index])+" $"+String.format("%8.2f",amtraise[index]));
  82. }
  83. }
  84. else if (response==2)
  85. {
  86. System.out.println("\nFundraiser Summary for "+nameT+" homeroom");
  87. System.out.println("---------------------------------------------");
  88. System.out.println(String.format("%-17s","Name:")+String.format("%-10s","Boxes:")+String.format("%-10s","Bonus:")+String.format("%-8s","Earned:"));
  89.  
  90. for (int i=0; i < names.length;i++)
  91. {
  92. stBoxes= (int)((amtraise[i]-bonus[i])/1.25);
  93. System.out.println(String.format("%-18s",names[i])+String.format("%-6s",stBoxes)+" $"+String.format("%4.0f",bonus[i])+" $"+String.format("%8.2f",amtraise[i]));
  94. }
  95.  
  96. System.out.println("---------------------------------------------");
  97. System.out.println(String.format("%-18s","Total")+String.format("%-6s",totalBoxes)+" $"+String.format("%4.0f",totalBonus)+" $"+String.format("%8.2f",totalEarn));
  98.  
  99. }
  100. else if (response==3)
  101. {
  102. System.out.println("Program Ended!");
  103. break;
  104. }
  105. else
  106. {
  107. System.out.println(response+" was not a valid choice");
  108. }
  109. }
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement