#Beginner java coder

1 messages · Page 1 of 1 (latest)

cunning walrus
#

what's wrong with my main and time object

package OOP;
import java.util.Scanner;


public class Time {
    public int toSeconds(int h, int m, int s) {
        int totalseconds = (h * 3600) + (m * 60) + s;
        return totalseconds;
    }
    

public void seconds() {
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter hours, minutes and seconds");
    String[] values = scanner.nextLine().split(" ");

    int h = Integer.parseInt(values[0]);
    int m = Integer.parseInt(values[1]);
    int s = Integer.parseInt(values[2]);

    Time time = new Time();
    int totalseconds = time.toSeconds(h, m, s);
    System.out.println("In only seconds that is: " + totalseconds);




public static void main(String[] arg) {
    Time time new Time();
    time.seconds();
    

    }
    
    scanner.close();

}
}
hearty fossilBOT
# cunning walrus what's wrong with my main and time object ```java package OOP; import java.util....

Detected code, here are some useful tools:

Formatted code
package OOP;

import java.util.Scanner;

public class Time {
  public int toSeconds(int h, int m, int s) {
    int totalseconds = (h * 3600) + (m * 60) + s;
    return totalseconds;
  }
  public void seconds() {
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter hours, minutes and seconds");
    String[] values = scanner.nextLine().split(" ");
    int h = Integer.parseInt(values[0] );
    int m = Integer.parseInt(values[1] );
    int s = Integer.parseInt(values[2] );
    Time time = new Time();
    int totalseconds = time.toSeconds(h, m, s);
    System.out.println("In only seconds that is: " + totalseconds);
    public static void main(String[] arg) {
      Time timenew Time();
      time.seconds();
    }
    scanner.close();
  }
}
#

<@&987246883653156906> please have a look, thanks.

vagrant latch
#

I got the wrong role.

cunning walrus
# steel crow what's the problem ?

void is an invalid type for the variable main on the main method and also on the Time time = new Time(); Duplicate local variable time

steel crow
#

it seems that you are mixing everything

cunning walrus
cunning walrus