Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. //Purpose: Calculate the overall occupancy rate for a hotel.
  2. //Input: # of floors, # of rooms per floor, # of rooms that are occupied
  3. //Output: # of rooms, # of rooms that are occupied and vacant
  4. //Overall occupancy rate for the hotel
  5. import java.io.*;
  6. import java.util.Scanner;
  7. import javax.swing.JOptionPane;
  8. import java.text.DecimalFormat;
  9.  
  10. public class proj6 {
  11. public static void main(String[] args) throws IOException {
  12. DecimalFormat f = new DecimalFormat ("#,##0.00");
  13. String fileInput;
  14. File myfile;
  15. Scanner sfile;
  16. int number = 0,sum = 0,max = 0,min = 100, Asum = 0, Bsum = 0;
  17. int Csum = 0, Dsum = 0, Fsum = 0, total = 0;
  18.  
  19. fileInput = JOptionPane.showInputDialog("Please enter the name" +
  20. "of the file that contains the grades");
  21. myfile = new file(fileInput);
  22. sfile = new Scanner(myfile);
  23.  
  24. while(sfile.hasNext()){
  25. number = sfile.nextInt();
  26. sum+=number;
  27. total++;
  28. if(number < min){
  29. min = number;
  30. }
  31. if(number > max){
  32. max = number;
  33. }
  34. if(number >= 90){
  35. Asum++;
  36. }
  37. else if(number >= 80){
  38. Bsum++;
  39. }
  40. else if(number >= 70){
  41. Csum++;
  42. }
  43. else if(number >=60){
  44. Dsum++;
  45. }
  46. else{
  47. Fsum++;
  48. }
  49. }
  50. JOptionPane.ShowMessageDialog(null, "Total number of midterm " +
  51. "grades: " + total + "\n The average midterm grade: " +
  52. sum/total + "\n The lowest midterm grade: " + min +
  53. "\n The highest midterm grade: " + max);
  54. JOptionPane.ShowMessageDialog(null, "The number of F midterms: " +
  55. Fsum + "\n The number of D midterms: " + Dsum + "\n The " +
  56. "number of C midterms: " + Csum + "\n The number of B" +
  57. " midterms: " + Bsum + "\n The number of A midterms: " +
  58. Asum + "||" + Asum/sum);
  59. }
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement