Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Logic for

Create a method ABC that takes two integer parameters, one for minutes and one for seconds, and prints the grade based on the following

15 Presentation is longer than 5 minutes and no longer than 7 minutes

10 Presentation is between 4 minutes 30 Seconds and 5 minutes OR between 7 minutes and 7 minutes and 30 seconds

Call from a main program.

What I have tried:

Java
public class ABC {

    public static String gradeTiming(int minute, int second) {
        String display;
        if (minute >=5 and <= 7); {
            display = "15";
        } 
        
        return String.format("%02d:%02d %s", minute, second, display);
    }
Posted
Updated 19-Oct-20 20:37pm
v2
Comments
Sandeep Mewara 20-Oct-20 1:39am    
And where are you stuck? Why are you not able to proceed?

Read carefully the requirements (for instance, ABC should be the name of the method, not of the class).
In order to implement the method logic, it is useful to convert minutes and seconds to, total seconds and use it.
Try

Java
public class MyGrader
{ 
  public static void ABC( int minutes, int seconds )
  {
    String grade = "unknown";
    int total_seconds = minutes * 60 + seconds;
    if ( (total_seconds >= 270 && total_seconds < 300) || (total_seconds >= 420 && total_seconds < 450))
      grade = "10";
    else if (total_seconds >= 300 && total_seconds < 420)
      grade = "15";
    System.out.println(grade);

  }

  public static void main( String args[])
  {
    ABC(4,35);
  }
}
 
Share this answer
 
Look here: Java Operators[^] - it covers the java logical operators &&, ||, and ! which provide what you need.
The word and in your code is wrong - you want to use the AND operator && instead, and the syntax is also incorrect:
Java
if (a >= 0 && a <= 10) {
   System.out.println("a is in range");
   }
Will give you a display provided a is between 0 and 10 inclusive.
Think about the question, and you'll get the idea!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900