Thread: Computer Science Java HW

Results 1 to 6 of 6
  1. #1 Computer Science Java HW 
    Registered Member
    Join Date
    Mar 2017
    Posts
    39
    Thanks given
    2
    Thanks received
    0
    Rep Power
    11
    Code:
    // user input methods, by datatype
        //---------------------------------------------------------------------------
        
        // get an int value
        public static int readInt(String prompt, boolean guiMode) {
            // TODO: add a second boolean input argument for a "guiMode",
            //         then wrap an if-else around the existing Scanner input below
            //       if F, get input as shown from Scanner (command line)
            //       if T, get input from JOptionPane (popup GUI) - YOU PROVIDE THIS CODE
        
        
            // set up data and objects
            Scanner input = new Scanner(System.in);
            int data = 0;        
            
            if (!guiMode) 
            {
            
            // prompt for an input int value
            System.out.print(prompt);
            data = input.nextInt();
            
            
            }
            else if (guiMode)
            {
             // prompt for an input int value
            
            
            data = Integer.parseInt(JOptionPane.showInputDialog(null, prompt));
    
            
    
            
            
            }
            
            return data;
            
           
        }

    this code about is completed and good.

    Code:
     // returns the age as of some REFERENCE date (2-input overloaded form, MODS NEEDED)
        public static int getAge(CS12Date dateBd, CS12Date dateRef) {
            int age = -1; // starter output
            
          
           
           
                   
            // TODO: calculate the age correctly, given birthdate AND a reference date
            //       1) take apart both input dates into MM, DD, YYYY using accessors --> 6 ints
            //       2) devise needed logic to calculate age for dateBd "as of" dateRef
            //         a) if dateBd is *after* dateRef in time (future BD), return -1 *and* print an error message
            //         b) do NOT print age from here, just return its value to the client
            
            return age;
            
            
         } // end 2-input overloaded version
    This is what I have to do modify this method to get age.










    this is the client of the program below

    Code:
    ublic static void main (String args[])
          {
          
         int month; 
         int day;
         int year;
       
         
            
              
           month = UtilsES.readInt("enter Birthday month:", false);
           day = UtilsES.readInt("Enter Birthday Day", false);
           year = UtilsES.readInt("Enter Birthday Year", false);    
           
           
           
           
     
          }


    My goal is to compare two dates for one date in the future. Uhh this is been a weird assignement can anyone give me some clues?



    https://pastebin.com/qMz9A4Ti - age client


    https://pastebin.com/rdjGqaX7 - cs12Date

    https://pastebin.com/hfWYwQHU - UtilsTest1ES


    link to all the codes


    My skype is InspiredProgramming



    https://www.scribd.com/document/3444...-Age-Utilities


    pdf of assignment
    Reply With Quote  
     

  2. #2  
    Renown Programmer
    Greg's Avatar
    Join Date
    Jun 2010
    Posts
    1,179
    Thanks given
    260
    Thanks received
    1,012
    Rep Power
    2003
    Quote Originally Posted by Eddies View Post
    My goal is to compare two dates for one date in the future. Uhh this is been a weird assignement can anyone give me some clues?
    Compare how? Number of seconds between the dates? Got to be more specific.
    Attached imageAttached image
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Mar 2017
    Posts
    39
    Thanks given
    2
    Thanks received
    0
    Rep Power
    11
    Reply With Quote  
     

  4. #4  
    🎶 As you're falling down 🎶


    uint32_t's Avatar
    Join Date
    Feb 2015
    Posts
    1,396
    Thanks given
    6,177
    Thanks received
    776
    Rep Power
    5000
    You forgot to edit out your name in one of the pastebins.
    Quote Originally Posted by Idiot Bird View Post
    Quote Originally Posted by Velocity View Post
    lol np mate looks like the community brought ur rep down to ur IQ
    Not too sure about that, it's at 0 . It would have to go minus to even be remotely close to his IQ.
    Reply With Quote  
     

  5. #5  
    Registered Member
    hacker's Avatar
    Join Date
    Jun 2013
    Posts
    1,409
    Thanks given
    576
    Thanks received
    580
    Rep Power
    5000
    dont even knw what ur trying to do.

    edit: u want to get age of someone using birthday inputted and current date?

    Code:
    
        private static Scanner inputScanner;
    
        public static void main(String[] args) {
            if (args.length != 1) {
                System.out.println("pls use cmd or gui arguements thx xd");
                return;
            }
    
            boolean guiMode = Boolean.parseBoolean(args[0]);
    
            if (!guiMode) {
                inputScanner = new Scanner(System.in);
            }
            int month = getInt("Enter Birthday month: ", false);
            int day = getInt("Enter Birthday Day: ", false);
            int year = getInt("Enter Birthday Year: ", false);
    
            LocalDate today = LocalDate.now();
            LocalDate birthday = LocalDate.of(year, month, day);
            Period period = Period.between(birthday, today);
            int years = period.getYears();
            System.out.println("hello u r " + years + " years old as of " + today.toString() + ". you will die in " + (years >= 60 ? "2 months sry" : (60 - years) + " years."));
    
        }
    
        public static int getInt(String prompt, boolean gui) {
            if (gui) {
                return Integer.parseInt(JOptionPane.showInputDialog(null, prompt));
            } else {
                System.out.print(prompt);
                return inputScanner.nextInt();
            }
        }
    amaze code yes. it uses java 8 so idk if u can use?
    Attached image
    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Mar 2017
    Posts
    39
    Thanks given
    2
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by hacker View Post
    dont even knw what ur trying to do.

    edit: u want to get age of someone using birthday inputted and current date?

    Code:
    
        private static Scanner inputScanner;
    
        public static void main(String[] args) {
            if (args.length != 1) {
                System.out.println("pls use cmd or gui arguements thx xd");
                return;
            }
    
            boolean guiMode = Boolean.parseBoolean(args[0]);
    
            if (!guiMode) {
                inputScanner = new Scanner(System.in);
            }
            int month = getInt("Enter Birthday month: ", false);
            int day = getInt("Enter Birthday Day: ", false);
            int year = getInt("Enter Birthday Year: ", false);
    
            LocalDate today = LocalDate.now();
            LocalDate birthday = LocalDate.of(year, month, day);
            Period period = Period.between(birthday, today);
            int years = period.getYears();
            System.out.println("hello u r " + years + " years old as of " + today.toString() + ". you will die in " + (years >= 60 ? "2 months sry" : (60 - years) + " years."));
    
        }
    
        public static int getInt(String prompt, boolean gui) {
            if (gui) {
                return Integer.parseInt(JOptionPane.showInputDialog(null, prompt));
            } else {
                System.out.print(prompt);
                return inputScanner.nextInt();
            }
        }
    amaze code yes. it uses java 8 so idk if u can use?

    Nah your code is too good, I just need someone to explain what my professor wants he can't explain it well enough, I hate online classes...

    Professor said I have to use the compare method to get the age, and call it from the client? I don't get it..
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Computer Science [Java] Homework. Heeelp! :D
    By Thunderous in forum Homework
    Replies: 12
    Last Post: 03-24-2015, 09:16 PM
  2. AP Computer Science
    By Benji in forum Homework
    Replies: 12
    Last Post: 02-09-2011, 10:51 PM
  3. Computer Science
    By Vault in forum Homework
    Replies: 5
    Last Post: 11-26-2010, 12:57 AM
  4. computer science homework
    By lt gangster in forum Homework
    Replies: 7
    Last Post: 11-02-2010, 11:53 PM
  5. Java hw!
    By Kc in forum Homework
    Replies: 2
    Last Post: 11-13-2009, 04:11 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •