Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Irvin Florencia

Greenhorn
+ Follow
since Apr 10, 2019
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Irvin Florencia

I'm writing a code for an assignment that has me use multiple methods in the main. The first method prints out a banner. The second method returns a string. In the second method, I'm meant to populate a string variable named productsCatalog with three different items of length 10. If the item is less than 10 letters we are meant to pad those items with spaces and then returns that string. The third method takes the string returned from the previous method and asks the user to enter an item to see if that item exists in the productsCatalog. If the items do exist in the productsCatalog then its meant to return true if not false. The first two methods in code work fine but the third only ask for the item from the user and then terminates and doesn't check if the item exists. Should I not use an if statement? Or is the problem elsewhere?

1 year ago


Im trying to write a code that uses 3 methods that follows specific guide lines. These are the guide lines:
The program uses methods to:

Get the numbers entered by the user
Calculate the average of the numbers entered by the user
Print the results with the whole number, a decimal, and two decimal positions
The first method should take no arguments and return a String of numbers separated by spaces.

The second method should take a String as its only argument and return a double (the average).

The third method should take a String and a double as arguments but have no return value.

For example, if the user input is...  20 40 60 80 100

...the program should give as output...  The average of the numbers 20 40 60 80 100 is 60.00

The first method does get a line of numbers form the user but I'm stumped as to how to writew a method that calualtes the average for thos numbers. I know the second method would have to have a sum oif the numbers entered and then that sum be divided by the numer of numbers entered. I dont how sum the numbers entered since thewy are in a string and dont know how to find the average, I hough of using .length() as a way toi find that average but that didnt work. Any iodeas?
1 year ago
How would I substring the first string since this string can be any length.
1 year ago
Im working on a code where the user is asked to enter two strings as input. The first string can be multiple words. The second would have to have a lenght of one. If the lenght is not one it would give the user feedback. If the string is of length 1 it would then have top use a while loop to check each position in the first string and return the number of times the character occurs. So if user enter apple and then a, it would say there is 1 occurence. I havve to use a while loop and just keep it simple. I though the code was correct but it doesnt return any occurences. I know the if statement validates the second string is a character long. Am i using the other stamentes wrong?

1 year ago
I made the adjustments and then added a second method that would calculate the average of each row. However, when I ran it gave me wrong results.



The program is supposed to take user input to fill the array and use three methods. the first method populates the 2d array while using nested while loop. The second calculates the average of the numbers in each row. And the last displays the numbers in the array and the average of each row. I don't what I'm doing wrong. I'm new to Java.
1 year ago
Im working on an assignment that requires me to populate a 2d array using a nested while loop? Any ideas on how this is done? The 2d array is 3x3
1 year ago
I was able to get it done after trying several things.
1 year ago
I tried writing it out and the only thing I could get was that after asking for input from the command line, I would put String userString = scnr.nextLine() as this would get the string from the input. I just don't know how to take that string and put it into the ArrayList as they are two different types.
1 year ago
Im trying to create a code that uses an ArrayList of Character data where the user enters a string and then each char in the string is represented as a separate character element in the list. Each character should them be displayed back in a separate line each.  This is what I have so far but don't know how to get the string and then get each individual char in that string.


import java.util.ArrayList;
import java.util.Scanner;
public class StringSlicer {

   
   public static void main(String[] args) {
       Scanner scnr = new Scanner(System.in);
       ArrayList<Character> userString = new ArrayList<Character>();
       
       System.out.println("Enter a word: ");
       
       while (scnr.hasNextLine()){
           userString.add(scnr.nextLine());
       }
       
       
   }
   
}
1 year ago
I'm working on an assignment where I have to use methods to get a list of numbers as a string type and then another method to calculate the average of those numbers provided. I have been able to write the method that asks for the numbers but I'm stuck as for how to get the average of those numbers. I know average would be sum / by the number of numbers provided.

hers is the code I have so far. Can anyone provide some feedback or how I should go about this? I'm new to Java but it is tough at times but don't want to give up.



1 year ago