Forum Settings
Forums
New
Oct 6, 2016 6:41 PM
#1
Offline
Mar 2013
61
Hi!

Good-day,

I need help with programming 2.

anyone willing to assist?

it's with the gui.
Oct 6, 2016 7:06 PM
#2

Offline
Sep 2013
2694
Maybe, but I need more deets. And seriously, guy, ask the goddamn question in the OP. Don't wait for replies before posting the info you have.
Oct 6, 2016 7:07 PM
#3
Offline
Mar 2013
61
Old_Raven said:
Maybe, but I need more deets. And seriously, guy, ask the goddamn question in the OP. Don't wait for replies before posting the info you have.



how to put this in coding:

"when the add/modify button is pressed
you take the information from the text fields, and then make an MP3 object using that data
Then you compare that MP3 object to the ArrayList that holds all of the other MP3 objects
If it exists, update the existing one
If it doesn't exist, add it"

I currently have a gui up and running.

but i dont know how to get my addormodifymp3
button to work to perform that task.
for my gui.
Oct 6, 2016 8:33 PM
#4

Offline
Sep 2013
2694
Ok well first of all, I'd change it from MP3 objects to MP3Name objects just because you're not comparing the actual bits in the Mp3 but the filename itself, but that's just me. Also, I'm very confused with what you mean by "update the existing one" considering you would just be inserting all the same characters again.

You say you have the GUI up so I'll just go off what I assume you have displayed.

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.JButton;


public class YourClass extends JFrame implements ActionListener
{
private JButton yourButton = new JButton("Add/Modify MP3");
private JTextField MP3NameField = new JTextField();
private List<String> MP3Names = new ArrayList<>();



public void YourClass()
{
this.add(this.MP3NameField);
this.add(this.yourButton);
}

@Override
public void actionPerformed(ActionEvent e)
{
int index = 0;
String temp_MP3Name; // this will hold the string within textfield
// MP3NameField


// store string from MP3NameField in temp variable for easy access
temp_MP3Name = this.MP3NameField.getText();

// ensure the list MP3Names isn't empty
if(!MP3Names.isEmpty())
{
// now loop through the list MP3Names for that MP3Name string
while(index < MP3Names.size())
{
// this ignores character case and compares the strings from the textfield and the
// string stored at a specific index in the list MP3Names
if(temp_MP3Name.compareToIgnoreCase(MP3Names.get(index)) == 0)
{
// if no differences between strings, update object at index
MP3Names.set(index, temp_MP3Name);
}else
{
// if differences between strings are found, consider this a new MP3 name and
// append it to the list MP3Names
MP3Names.add(temp_MP3Name);
}

index++;
}
}
}
}


gods I hope my formatting sticks.

edit: Nope. Formatting didn't stick :(
Old_RavenOct 6, 2016 8:38 PM
Oct 11, 2016 1:30 PM
#5
Offline
Oct 2015
13
Chihiya said:
anyone willing to assist?

I don't mean to be rude but @Old_Raven offered some help (that is commented to help you understand it) and you didn't even acknowledge his last response. If you show you're willing to put in the effort then people will be more inclined to help you e.g. try some code and report back with what you've got and people can offer input. Right now all you've really said is you're stuck with x, send help.

All you're doing is:
Text input/output handling (with no error validation either) - 100s of tutorials on this
Interacting with a list with an if else statement - 100s of tutorials on this too
Creating an mp3 object that hold one string (? or more strings, cba to re-read) - 100s on tutorials on this

If you can make an attempt at the above you'll either get it correct, get it wrong and we can correct you. That being said we won't give you the answer because it won't help you progress and learn the language.

P.S Next time say what error you have, in this case it didn't really matter but it does matter.
FringieOct 11, 2016 1:34 PM
Oct 11, 2016 1:40 PM
#6
Offline
Mar 2013
61
Fringie said:


I saw his response and we both chatted via message.


P.S I can't say exactly what error I have in netbeans that why I had msged old_raven to take a look at it.

xD
Oct 11, 2016 1:45 PM
#7
Offline
Oct 2015
13
Chihiya said:
Fringie said:


I saw his response and we both chatted via message.


P.S I can't say exactly what error I have in netbeans that why I had msged old_raven to take a look at it.

xD

Oh right, my bad. I assume you both got it working then?
Oct 11, 2016 6:42 PM
#8
Offline
Mar 2013
61
Fringie said:
Chihiya said:

I saw his response and we both chatted via message.


P.S I can't say exactly what error I have in netbeans that why I had msged old_raven to take a look at it.

xD

Oh right, my bad. I assume you both got it working then?

actually his/her(idk the gender)
coding wasn't working 100%.

So i had to go on youtube

to figure it out.

But yes he/she was rite about the mp3 object.
Oct 12, 2016 2:32 PM
#9
Offline
Oct 2015
13
Chihiya said:
Fringie said:

Oh right, my bad. I assume you both got it working then?

actually his/her(idk the gender)
coding wasn't working 100%.

So i had to go on youtube

to figure it out.

But yes he/she was rite about the mp3 object.

Feel free to show me some code (in this thread) that you're having troubles with and I'll give you some help. Just say what you want the code to do and provide the code you've made to try to do that.
Oct 12, 2016 7:47 PM

Offline
Mar 2014
4946
need help

The GArt store has asked you to implement a computer program to determine the number of cans
of paint, along with the cost, to paint a room of a given size with a given color. To simplify the design
of the program and to learn about modularity, write this program using several methods.

Method 1: This method will get input from the user: one dimension of the room. Assume the room
has 4 walls and a ceiling to paint and is rectangular. Two walls will have size height*length and two
will have height*width. The ceiling’s size is length*width. The floor will not be painted. This
method is passed two parameters, a String parameter indicating which dimension is being requested
(height, length, or width), and a Scanner. Both the String and the Scanner will be declared in main.
The String will be used in a prompt to inform the user which dimension to enter. The Scanner will be
used an input statement. This method will then get the input from the user as an int, stored in a
temporary variable like result from method 3 of part 1 of this lab. This value will be returned. You
will call this method 3 times, once for height, once for length and once for width in order to get the 3
dimensions of the room.


public static int getSize( String caption, Scanner input )
{
System.out.print("Enter the " + caption + " of the room: ");
int value = input.nextInt();
return value;
}
Oct 15, 2016 7:01 PM
Offline
Oct 2015
13


What do you need help with? I'll assume you don't know how to use that method?

Here's an example of how you would use the method:
public static void main(String[] args) 
    {
        Scanner sc = new Scanner(System.in); //<- Creates a object of type 'Scanner' that can take in input values 
        int roomLength = getSize("length", sc); // <- store the length in the variable named 'roomLength', get the length from the getSize method
        System.out.println("The length of the room is: " + roomLength); 
    }
    public static int getSize( String caption, Scanner input )
    {
    System.out.print("Enter the " + caption + " of the room: ");
    int value = input.nextInt();
    return value;
    }
Oct 16, 2016 1:46 AM

Offline
Mar 2014
4946
I've already got it.
Oct 16, 2016 7:30 AM
Offline
Mar 2013
61
sullynathan said:
I've already got it.


what was it,sullynathan?

OwO
Oct 16, 2016 10:56 AM

Offline
Mar 2014
4946
In main, I have height, width, and length values and called it back into the 2nd method.
Oct 23, 2016 9:19 PM
Offline
Mar 2013
61
sullynathan said:
In main, I have height, width, and length values and called it back into the 2nd method.

Okay doki.aThat's cool.
Oct 24, 2016 12:53 AM

Offline
Mar 2014
4946
Chihiya said:
sullynathan said:
In main, I have height, width, and length values and called it back into the 2nd method.

Okay doki.aThat's cool.

another one


This is all my code. I am having problems with the standard deviation formula. I run the program with these values:

Number of items: 5

Items: 16 25 81 80 24

I'm supposed to get this output:

Average: 45.20

Std Dev: 32.41

Less than Avg: 3

Array is not in sorted order

Instead, I get this output:

Array is not in sorted order

Average: 45.20

Std Dev: 55.60

Less than Avg: 3

import java.text.DecimalFormat;
import java.util.Scanner;
public class array {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat ("#.00");
System.out.println("How many values do you want?");
int num = input.nextInt();
if (num< 1 || num > 100)
{
System.out.println("Error");
System.exit(0);
}
int[] array= valueArray(input, num);
double o= average(num, array);
double standdev = getStdDev(array, num);
int lessThanAvg = lessAvg ( array, num, o );
boolean sorted=isArraySorted(array, num);
System.out.println("Average: " + df.format(o));
System.out.println("Std Dev: " + df.format(standdev));
System.out.println("Less than Avg: " + lessThanAvg);
}

public static int[] valueArray (Scanner input, int num )
{
int[] values = new int[100];
System.out.println("What numbers do you want to put in?");
for (int j = 0; j < num; j++)
{
values[j]=input.nextInt();

}
return values;
}
public static double average ( int num ,int[] values)
{
double avg=0.0;
for (int i = 0; i < num; i++)
{
avg = avg+values[i];
}

return avg/num;
}

public static double getStdDev (int [] values, int num)
{
double avg = 0.0;
double sum = 0 ;
for (int i = 0; i < num - 1; i++)
{

sum = Math.sqrt ((Math.pow((values[i]-avg),2) + Math.pow((values[num-1]),2)) / num-1);


}
return sum;

}
public static int lessAvg ( int [] values, int num, double avg )
{
int counter = 0;
for (int i = 0; i < num; i++ )
{
if (values[i] < avg)
{
counter = counter + 1;
}
}
return counter;
}
public static boolean isArraySorted (int [] values, int num)
{
for (int i = 0; i < num - 2; i++)
{
if (values[i]>values[i+1])
{
System.out.println("Array is not in sorted order");
return false;

}
}

System.out.println("Array is in sorted order");
return true;
}

More topics from this board

» Gacha Survey ( 1 2 )

Shizuna - Apr 11

56 by BitChilly »»
1 hour ago

» Looking for more Anime Pixel Games

Astachanna - Apr 4

12 by Astachanna »»
1 hour ago

» Last game you purchased ( 1 2 3 4 5 ... Last Page )

Completely_Numb - Mar 15, 2014

525 by Timeline_man »»
2 hours ago

» Stellar Blade Preview: Sekiro Meets NieR: Automata?

deg - Feb 1

28 by Shizuna »»
4 hours ago

» Add "you little bitch" to a video game quote. ( 1 2 3 )

Kajiuran - Oct 20, 2023

141 by Kajiuran »»
9 hours ago
It’s time to ditch the text file.
Keep track of your anime easily by creating your own list.
Sign Up Login