Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Need Java help on this detail attached

  1. #1
    Junior Member
    Join Date
    Jun 2019
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need Java help on this detail attached

    Last Name: Johnson
    First Name: Scott J

    City: Detroit


    1) Using the const key word create two arrays, with the variable names ‘oddArray’ and ‘evenArray’.
    a. Use this ‘oddArray’, [‘5’, ‘7’. ‘1’, ‘3’], for your assignment.
    b. Use this as your ‘evenArray’, [‘0’, ‘6’. ‘4’, ‘2’], for your assignment.
    2) You will create an object with a variable name called ‘initialObj’. Inside this object you will assign three attributes (key-value pairs).
    a. One of the attributes will be called ‘city’, the value for this attribute is shown in the webphone data under the city.
    b. Next attribute will be called ‘name’, the value for this attribute will be the concatenation of what is shown under first name and last name in webphone. If there is middle initial in the name include that as well. For example if first and last name is only present the value will be “John Doe” (with a space between first and last name). If there is a middle initial in the webphone, the value will be “John J Doe” (space between first name and middle initial, and a space between middle initial and last name).
    c. Next attribute will be called ‘defaultValue’. Set its value to number 2.

    3) Next, you will create a variable called ‘numberOfNames’ in which you will assign number of names that is in the name attribute of the initialObj. For example, if my name consists of ‘Jeswin Abraham’, the value will be 2, if my name contains ‘Jeswin J Abraham’, the value will be 3. This must be done dynamically and programmatically. Hardcoded values will not be accepted.
    4) Then, you will create a constant variable called ‘cityLength’ that stores the length of the characters of the city attribute in the initialObj.
    5) Next, create a constant variable called ‘index’. Its value will be ‘cityLength’ divided by ‘numberOfNames’ rounded to the nearest integer.
    6) Using the variable ‘cityLength’, determine if the integer is an odd number or even number.
    7) Create a const variable called ‘parityOfCity’, and assign the value ‘odd’ or ‘even’ based on the value found in step 6.
    8) Create a variable called ‘result’.
    a. Its value would be set by using the value of ‘index’ to access the element of the appropriate array.
    b. The appropriate array will be determined by the value of ‘parityOfCity’.
    c. If the index value is greater than the length of the array, then programmatically default to the last element of the array.

    9) Now create an object called ‘finalObj’, and assign the values of initialObj to the final Obj.
    10) Modify the ‘defaultValue’ in the finalObj by adding the values of ‘defaultValue’, and ‘result’. For example, if my ‘defaultValue’ variable is 2, and my ‘result’ variable is ‘7’, the combined value will be 9 (2 + 7).
    11) Now write a console.log statement for both the ‘initalObj’ and ‘finalObj’.
    12) If the finalObj.combinedValue and initalObj.value have the same values, then the solution is incorrect. The initialObj must preserve its initial values, only the finalObj will have the new concatenated values.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need Java help on this detail attached

    Do you have any specific java programming questions?

    Be sure to wrap any posted code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    quadatic20 (June 12th, 2019)

  4. #3
    Junior Member
    Join Date
    Jun 2019
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need Java help on this detail attached

    var oddArray = ['5','7','1','3'];
    var evenArray = ['0','6','4','2'];

    const initialObj = {
    'city': 'Detroit'
    'name': 'Scott J Johnson'
    'defaultValue': 2
    };

    var numberOfNames = {

    };

    const cityLength = {

    };

    const index {

    };

    var parityOfCity = {

    };

    var result = {

    };



    const finalObj = {
    'city': 'Detroit'
    'name': 'Scott J Johnson'
    'defaultValue': (defaultValue + result)
    };

    console.log(initialObj);
    console.log(finalObj);


    New to java and this forum -- sorry if posted to wrong thread

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need Java help on this detail attached

    That code looks like javascript, not java. They are different.
    Try asking your questions on a javascript forum.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #5
    Junior Member
    Join Date
    Jun 2019
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Need help on the following java

    if (partyOfCity === 'even') {
    var tempEvenLength = evenArray.length;
    var tempOddLength = oddArray.length;
    if (index > evenArray.length) {
    var result = Number(evenArray[evenArray.length]);
    } else {
    var result = Number(evenArray[index]);
    }
    } else {
    if (index > tempOddLength) {
    var result = Number(oddArray[oddArray.length]);
    } else {
    var result = Number(oddArray[index]);
    }
    }

  7. #6
    Junior Member
    Join Date
    Jun 2019
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need Java help on this detail attached

    HELP NEEDED!!

    if (partyOfCity === 'even') {
    var tempEvenLength = evenArray.length;
    var tempOddLength = oddArray.length;
    if (index > evenArray.length) {
    var result = Number(evenArray[evenArray.length]);
    } else {
    var result = Number(evenArray[index]);
    }
    } else {
    if (index > tempOddLength) {
    var result = Number(oddArray[oddArray.length]);
    } else {
    var result = Number(oddArray[index]);
    }
    }
    Last edited by quadatic20; June 21st, 2019 at 06:16 PM. Reason: help

  8. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need Java help on this detail attached

    Ask your instructor if the assignment is to be written in javascript or in java.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. the Book a Java course for beginners and explain the code in detail
    By risboten in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: July 15th, 2018, 04:05 AM
  2. How to preview attached files using Servlets
    By ramesh250578 in forum Java Servlet
    Replies: 1
    Last Post: September 25th, 2014, 04:39 AM
  3. Assignment - Question attached. not sure how to add customer class
    By Mattz0r in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 24th, 2014, 05:19 PM
  4. detail
    By ashish1765 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 9th, 2012, 08:57 AM
  5. Http 404 Error - Img attached
    By narayanyr in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 16th, 2012, 08:57 PM