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 2 of 2

Thread: Intro. to Java Help.... In Danger of Failing Class

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Intro. to Java Help.... In Danger of Failing Class

    Hello talented programmers! I'll cut straight to the chase: I thought I wanted to get into programming, but I SUCK at it. I tried going to extra help, and I tried to learn things on my own, but I just CANNOT figure it out. I have 5 projects I could not complete that's due next Wednesday, and I seriously cannot fail this class. So, I was wondering if you guys could help me out. Thanks!

    *I'm not trying to weasel my way out of doing my work. Everything I handed in, I got a 0 or 65. I am truly desperate guys. Thanks.

    1. [Find the largest] Many of our programs will require reading several integers from the user and storing them in an array. In the next set of in-class lessons, you will learn an efficient method for doing this. For now, you can use the code given in the problem below.

    Complete and test the following code. Your program should read 3 integers from the user, store them in an array, and then print the largest of the three values. If there is a tie for the greatest value, just print that value.

    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int[] array = new int[3];
    //Read 3 integers from the user and store in an array
    System.out.print("Enter 3 integers: ");
    array[0] = input.nextInt();
    array[1] = input.nextInt();
    array[2] = input.nextInt();

    //TYPE YOUR CODE HERE
    }

    When run, you should get results like:

    Enter 3 integers: 7 23 11
    Largest value is 23


    Enter 3 integers: 18 3 18
    Largest value is 18


    2. [Lucas numbers] In mathematics, Lucas numbers are values that form a sequence such that each number is the sum of the previous two numbers. The most famous sequence of Lucas numbers are the Fibonacci numbers, which start with 1 and 1:

    1 1 2 3 5 8 13 21 34 55 89 144 …

    However, Lucas numbers can start with any two values, such as 1 and 3:

    1 3 4 7 11 18 29 47 76 123 …

    Write a program which starts by creating an array that can hold 6 integers. Then, read two integers from the user and place them in index locations 0 and 1 of the array. Next, fill the final 4 spaces in the array with the next four Lucas numbers, according to the rule above. Finally, print your array (using the print function given at the beginning of this assignment). Here is some example output:

    Enter first number: 2
    Enter second number: 5
    2 5 7 12 19 31


    3. [Rotate an array] Write a program which reads 3 numbers from the user and stores them in an array. Then, print the array. Next, move the first element of the array to the end of the array, moving all other elements left one space. To do this, you'll need to use a version of the "swapping" algorithm described in class. Print the array again. Rotate the elements once again (you can copy-and-paste your code). Finally, print the array one more time. Sample output:

    Enter 3 numbers: 8 2 13
    8 2 13
    2 13 8
    13 8 2


    4. [Inventory simulator] You run a store which sells three products:
    1. cheeseburgers
    2. spaghetti
    3. blankets
    You're going to write a program which simulates keeping track of how many of each you have in stock. Here is some sample output:

    Welcome to Wally-Mart!
    We currently have:
    1. Cheeseburgers – 247
    2. Spaghetti - 182
    3. Blankets - 27
    Enter your order by number (1-3): 2
    We now have:
    1. Cheeseburgers – 247
    2. Spaghetti - 181
    3. Blankets - 27

    Here’s how the order of things in your code should go:
    1. Create an array using an array initializer, storing all 3 of the starting inventory numbers.
    2. Print welcome
    3. Print inventory
    4. Ask for order from customer
    5. Decrement the appropriate element of the array
    6. Print the inventory again (you can copy-and-paste your code from above)

    Step 4 is important. You must change the appropriate number in the array. You may not simply print one less than the number in the array. The code for steps 3 and 6 must be identical.

    For step 5, do not use an else-if tree. Use the number that the user types as the index to the array. Just remember that item #1 is stored in location index 0, item #2 is in index 1, etc. As a hint, understand how the following code works (it isn’t exactly what you need to do, but it’s similar:
    System.out.print(“Enter a number: “);
    int num = input.nextInt();
    //increment space in the array 2 to the right of location (num):
    array[num+2] = array[num+2] + 1;

    After you have your code working, change the numbers in step 1 above, and make sure your code still works.


  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Intro. to Java Help.... In Danger of Failing Class

    what have you tried now? do you have errors or bugs in your code? Unfortunately, we cannot (and don't want to) give the answer or provide a code for your exams. Just give a little effort, then ask specific question and I'm sure someone here is going to assist you. it is better to create different threads with your different activities. you have plenty of days till next wednesday, you can do it.

Similar Threads

  1. My Java program is failing to run in command prompt
    By George Mawire in forum What's Wrong With My Code?
    Replies: 26
    Last Post: January 24th, 2014, 07:54 AM
  2. Intro to Java problem! Please help!
    By ParadoxPB in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 21st, 2013, 01:03 PM
  3. Intro to Java
    By omen1090 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 4th, 2013, 07:37 AM
  4. Intro to java assignment help
    By Rahiant in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 20th, 2012, 01:05 PM
  5. Intro to java hw assignment
    By coke32 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 7th, 2011, 07:45 AM

Tags for this Thread