Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Purpose: Calculate the overall occupancy rate for a hotel.
- //Input: # of floors, # of rooms per floor, # of rooms that are occupied
- //Output: # of rooms, # of rooms that are occupied and vacant
- //Overall occupancy rate for the hotel
- import java.io.*;
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- import java.text.DecimalFormat;
- public class proj6 {
- public static void main(String[] args) throws IOException {
- DecimalFormat f = new DecimalFormat ("#,##0.00");
- String fileInput;
- File myfile;
- Scanner sfile;
- int number = 0,sum = 0,max = 0,min = 100, Asum = 0, Bsum = 0;
- int Csum = 0, Dsum = 0, Fsum = 0, total = 0;
- fileInput = JOptionPane.showInputDialog("Please enter the name" +
- "of the file that contains the grades");
- myfile = new file(fileInput);
- sfile = new Scanner(myfile);
- while(sfile.hasNext()){
- number = sfile.nextInt();
- sum+=number;
- total++;
- if(number < min){
- min = number;
- }
- if(number > max){
- max = number;
- }
- if(number >= 90){
- Asum++;
- }
- else if(number >= 80){
- Bsum++;
- }
- else if(number >= 70){
- Csum++;
- }
- else if(number >=60){
- Dsum++;
- }
- else{
- Fsum++;
- }
- }
- JOptionPane.ShowMessageDialog(null, "Total number of midterm " +
- "grades: " + total + "\n The average midterm grade: " +
- sum/total + "\n The lowest midterm grade: " + min +
- "\n The highest midterm grade: " + max);
- JOptionPane.ShowMessageDialog(null, "The number of F midterms: " +
- Fsum + "\n The number of D midterms: " + Dsum + "\n The " +
- "number of C midterms: " + Csum + "\n The number of B" +
- " midterms: " + Bsum + "\n The number of A midterms: " +
- Asum + "||" + Asum/sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement