Total de visualizações de página

sábado, 11 de dezembro de 2010

Data and Expressions

Laboratory #4: Data and Expressions - Review

Laboratory #4: Data and Expressions - Review

Part I. Computing Averages.

Write a program that reads three grades and prints the average.
a.      Read 3 values from the user.
b.      Calculate the average and display it.

Part II.  Converting Fahrenheit to Centigrade’s.

Write a program that converts degrees from Fahrenheit to Centigrade’s.
c.      Read the Fahrenheit value from the user.
d.      Convert the Fahrenheit degrees to Centigrade’s and display it.
e.      Use Google to find the conversion formula.

Part III.  From seconds to hours, minutes, seconds.

Write an application that reads values representing time duration in seconds, then print the equivalent in hours, minutes and seconds.  For example, 9999 seconds is equivalent to 2 hours, 46 minutes and 39 seconds.


// Nilton Soares - September, 27th 2010 - CS 120
// Program to Display Grades Results
import java.util.Scanner;

public class Gradesresult
{
  public static void main(String args[])
  {
        
       double grade=0.0;
       Scanner scan = new Scanner(System.in);   
       System.out.print("Enter the Grade (0-100): ");
       String grade=scan.next();
            
      
       while (grade<0.0 || grade>100.0)
       {
       System.out.print("Enter a valid Grade (0 to 100): ");
       grade=scan.nextDouble();
       }
       if (grade>=90.0 && grade<=100.0)
             System.out.print("Excelent!! Your grade is "+grade+"! You got A!");
       if (grade>=80.0&&grade<=89.0)
             System.out.print("Good!! Your grade is "+grade+"! You got B!");
       if (grade>=70.0&&grade<=79.0)
             System.out.print("Your grade is "+grade+"! You got C!");
       if (grade>=60.0&&grade<=69.0)
             System.out.print("Your grade is "+grade+"! You got D!");
       if (grade>=0&&grade<=59.0)
             System.out.print("Your grade is "+grade+"! You got F!");
      
  }
 
}

// Nilton Soares - September, 27th 2010 - CS 120
// Massbay - Professor Susanne Steiger-Escobar
// Program to Display Fahrenheit to Centigrade’s
import java.util.Scanner;
public class Fahrenheit_centigrade
{
  public static void main(String args[])
  {
        
       int temp_f,temp_c;
             
       Scanner scan = new Scanner(System.in);   
       System.out.print("Enter the Temperature in F: ");
       temp_f=scan.nextInt();
       temp_c=((temp_f-32)*5/9);  //Deduct 32, then multiply by 5, then divide by 9
       System.out.println("The Temperature in C is : "+temp_c);  
      
  }
 
}
// Nilton Soares - November, 19th 2010 - CS 120
// Massbay - Professor Susanne Steiger-Escobar
// Class to keep track of time by keeping h,m,s

public class Time1
{
  /**
   Initializes the Class Time Variables
   hour as integer
   minute as integer
   second as integer
   */
  private int hour;   // 0 - 23  
  private int minute; // 0 - 59  
  private int second; // 0 - 59  10   
 
  /**
   * Validate hour 0-23
   * Validate Minute 0-59
   * validade Second 0-59
   */
 
  public void setTime( int h, int m, int s ) 
  {
    hour = ( ( h >= 0 && h < 24 ) ? h : 0 );
    minute = ( ( m >= 0 && m < 60 ) ? m : 0 );
    second = ( ( s >= 0 && s < 60 ) ? s : 0 );
  }
  // convert to String in universal-time format (HH:MM:SS)
  public String timeOfDay(int h) 
  {
    String timeday="tessrsrsdte";
    //timeday= ((h == 5) ? "Dawn":"");
    //timeday= ((h >= 6 && h < 11) ? "Morning":"");
    //timeday= ((h >= 12 && h < 17) ? "Afternoon":"");
    //timeday= ((h >= 18 && h < 19) ? "Evening":"");
    //timeday= ((h > 19 && h < 5) ? "Night":"");
    return "dsdsds";
  }
    //Provide a method timeOfDay() that returns the string “dawn”, “morning”, “afternoon”, “evening” or “night” depending on the time of the day.
    //  ·        Provide a method isMorning() that returns true if it is morning.
     
     
     
      public String toUniversalString() 
    {
      return String.format( "%02d:%02d:%02d", hour, minute, second ); 
    } // end method toUniversalString 
    // convert to String in standard-time format (H:MM:SS AM or PM)
    public String toString() 
    {
      return String.format( "%d:%02d:%02d %s",             
                           ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ), 
                           minute, second, ( hour < 12 ? "AM" : "PM" ) );    
    } // end method toString 
  } // end class Time1

Nenhum comentário:

Postar um comentário