2 Replies - 1338 Views - Last Post: 09 October 2012 - 09:01 PM Rate Topic: -----

#1 ayenbobo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-October 12

Question : is my code is right or node

Posted 09 October 2012 - 12:46 AM

my assignment question
=================
CAR PARK SYSTEM
===FROM======
Insert Day :
Insert Month :
Insert Year :
Insert Hour :
Insert Minute :
=====TO======
Insert Day :
Insert Month :
Insert Year :
Insert Hour :
Insert Minute :
=================
FROM 9/8/2012 8.00 TO 10/8/2012 3.00
TOTAL PARKING TIME >> 1 DAY 8HOURS
TOTAL PAY >> RM36

This is my coding, so far i only done coding for day,month and year.i want to know if the coding is right or wrong because i think something wrong.so far the coding that i search in the internet is mostly about current date and for user to insert date is hard to find. anyone can help.

import java.util.*;
import java.text.*;
class  CarPark{
   public static void main(String[] args){

     Scanner input=new Scanner(System.in);
     System.out.print("\nEnter Day(1-31): ");
     int dd=input.nextInt();
     System.out.print("Enter Month(1-12): ");
     int month=input.nextInt()-1;
     System.out.print("Enter Year: ");
     int year=input.nextInt();

     System.out.println("From : "+dd+"/"+(month+1)+"/"+year);
     }
}

This post has been edited by Atli: 09 October 2012 - 01:09 AM
Reason for edit:: Please use [code] tags when posting code.


Is This A Good Question/Topic? 0
  • +

Replies To: Question : is my code is right or node

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2675
  • View blog
  • Posts: 11,297
  • Joined: 20-September 08

Re: Question : is my code is right or node

Posted 09 October 2012 - 06:50 AM

Quote

i want to know if the coding is right or wrong because i think something wrong

The way to find out is to compile and run it. A word of caution - Java months are zero-indexed in the API
Was This Post Helpful? 0
  • +
  • -

#3 ayenbobo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-October 12

Re: Question : is my code is right or node

Posted 09 October 2012 - 09:01 PM

View Postg00se, on 09 October 2012 - 06:50 AM, said:

Quote

i want to know if the coding is right or wrong because i think something wrong

The way to find out is to compile and run it. A word of caution - Java months are zero-indexed in the API


i already compile and run it. then how to convert input from user to date because i need display like this (from : 25/03/2011 04:00 to: 26/03/2011 14:00) after that i need to calculate the total day and time between 'from' and 'to'
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1