BestJewSinceJC 700 Posting Maven

I get the concept, I just don't understand specifics of how it happens. I'm thinking a possible exam question on my OS test would be something like "what is a system call and how does it work". I can answer the first part, but not the second part. And when you say "from the outside world" that sounds like... a hardware interrupt?

edit:

I just found something that I think will help: something called the "time quantum" and the timer interrupt handler for Linux. It says once the time quantum expires, the process gets preempted... which is something like what I'm looking for, so I think it'll yield some answers. Consider this solved for now, and thanks for the help Salem.

BestJewSinceJC 700 Posting Maven

Yeah, I think 20% is ridiculous personally, but considering that most people who get tips live off of those tips, I usually do not dip below 15% unless their service was particularly bad. I thought the arguments put forth about tipping in Reservoir Dogs were pretty interesting. At some point, a mediocre waiter/waitress deserves something, but I don't think that something is 20%.

BestJewSinceJC 700 Posting Maven

Being 'random' doesn't necessarily mean it will be diverse over one try. But if you were to run it millions of times, you would see that the numbers would show up much more evenly. The for loop you have just defines how many times something happens. So

for (int i = 0; i < 10; i++){
//this happens 10 times!
}

for (int i = 1; i < 11; i++){
//this also happens 10 times!
}

However, you defined your Random as "bingo.nextInt(75)" which tells the random number generator to randomly generate a number between 0 and 74. Check out the link I just gave you - if you go to the nextInt(int) method, it says what I just told you. If you want your number to be between 1 and 75 you'd have to say

int result = bingo.nextInt(75) + 1;
BestJewSinceJC 700 Posting Maven

right click on the desktop
click personalize
in the bottom left, under "see also" it says "taskbar and start menu"

I think you'll be able to get it from there.

BestJewSinceJC 700 Posting Maven

I was always brought up that 15% tip was a standard rate. So it was surprising when my mom argued with me today that it is now considered rude to tip 15% and that 20% is now the standard tip. This is after I expressed surprise at her tipping over 20% for mediocre service from a delivery man. I have nothing against tipping, but to me, 15% is for average service, higher or lower for better or worse service. Since tipping goes by percentage I don't see any logic behind this supposed change. Being a college student I might be out of the loop. Thoughts?

BestJewSinceJC 700 Posting Maven

So like, the exact thing you posted yesterday? Except that yesterday you had a different explanation of your problem. I don't know what it means to "make a JButton generate a coding" so you may want to ask clear questions and provide examples, otherwise, you won't get many enlightening replies.

edit: And even if you didn't like the reply I gave you yesterday, if it didn't make sense to you, or you thought it was stupid, you could at least reply back with something clarifying your issue, or disagreeing with me, or whatever. Not replying at all then posting a new thread on what seems to be the same topic is rude IMO.

BestJewSinceJC 700 Posting Maven

Since you only need one space in the center of the card, it would be pointless to use "%" to do that. Just figure out which iteration of the for loop you need to put the space at. Then say

if (row == 3 && column == 3) System.out.print(" ");

That's just an example, I don't know the exact row and column to put it at, but that might be it.

BestJewSinceJC 700 Posting Maven

Ok, then consider this example:

for (int i = 0; i < 25; i++){
if (i % 5 == 0) System.out.println();
}

If that doesn't make sense, look up the "modulus" operator on google. (Which is the operator I used above that looks like a percent sign).

BestJewSinceJC 700 Posting Maven

So do you want the placement of the new line to be randomized? Or do you want it to look a certain way? You've just suggested two different things...

BestJewSinceJC 700 Posting Maven

Or even more simply you can just click

Start->run->cmd (click enter). Then the command window will open. From there lets say you are in the directory C:\Users\Kyle. Typing "cd .\Documents" will take you to the C:\Users\Kyle\Documents directory.

Short answer: use the "cd" command to change directory.

BestJewSinceJC 700 Posting Maven

You have most of the correct code.

import java.util.Scanner;
import java.io.*;

/**
   
*/

public class ChargeAccountValidation
{
   public static void main(String[] args) throws IOException
   {
      final int SIZE = 50;
      int[] numbers = new int[SIZE];
      int result, searchValue;
      
      int index = 0;
      
      // Open the file.
      File file = new File("accounts.txt");
      Scanner inputFile = new Scanner(file);

         while (inputFile.hasNextInt() && index < numbers.length)
         {
            numbers[index] = inputFile.nextInt();
            System.out.println(numbers[index]);
            index++;
         }

      }
      // Close the file.
      inputFile.close();
   }
}

I only changed a few things: removed the for loop, initialized the index to 0, and changed the while loop's condition from hasNext() which will match basically anything to hasNextInt() which will match only an int. Alternatively you could use a for loop to do this, but combining a while & a for makes no sense:

for (int index = 0; index < numbers.length; index++){
if (inputFile.hasNextInt()) numbers[index] = inputFile.nextInt();
}
BestJewSinceJC 700 Posting Maven

http://theoatmeal.com/comics/computers

I found that pretty funny, as well as the oatmeal's comic about printers. It might be old news to some of you but I don't frequent the site so I tend to forget it exists until a friend shows me a link.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

4 years ago they might have helped you create it. Now - doubtful. But I'm sure nobody else is going to help you. And btw, you don't use Math.pow() to generate random numbers.

BestJewSinceJC 700 Posting Maven

What I've learned so far: An OS may trigger a software interrupt by executing a system call. According to what I read online, this is implemented via special instructions such as INT that the CPU can execute. I also understand how interrupts get handled by the interrupt service routine.

My question: since the CPU can only execute one instruction at a time, how does it work? For example, lets say a program X was hogging the CPU resources. The OS would have to execute a software interrupt to regain control of the CPU, but how would it do this (since the CPU is already executing instructions)?

Thanks for any explanations.

BestJewSinceJC 700 Posting Maven

It will only call the handleClick() method of the Object that was instantiated. I think it does what you are talking about - go try it out and let me know.

BestJewSinceJC 700 Posting Maven

I agree with you, mainly, but what did that 'hijack' thread have to do with people who don't show effort on homework assignments? I thought the whole 'hijack' thing was about threads that had gotten split or something like that. Guess I'm out of the loop...

BestJewSinceJC 700 Posting Maven

I rarely find the site slow. Maybe you guys should upgrade your ISP, hmm? But I agree with you on the reply box - occasionally I'm fooled into that too. But the real solution is to remember to check whether or not you're logged in before you try to post.

To add another very minor annoyance, we now have to wait 15s between up or down voting. And also reload the page in between, since it doesn't know when 15s have passed otherwise.
Suggestion:

if (member.post_count > 1000) //vote all you want!!!

:)

BestJewSinceJC 700 Posting Maven

Create an interface called ClickHandler. Have all of your classes (that you want to execute code when the thing is clicked) implement the ClickHandler interface. The ClickHandler interface should have one method called handleClick(). Each of your classes can provide their own implementation of handleClick(). Now, in your base class, you can keep an ArrayList of Objects that want to be notified when a click happens. You can then loop through the ArrayList and for each Object in the ArrayList, call the handleClick() method.

edit:
Here is an example of what I am talking about. You can actually credit one of our mods, Ezzaral, with coming up with this example (he gave it to me as advice a year or so ago, I think it might clarify things for you).

import java.util.ArrayList;
import java.util.List;

public class mainTest {

    public static void main(String[] args) {
        Model model = new Model();
        View view = new View();

        /** add the view as a listener */
        model.addListener(view);

        /** do something to the model */
        model.updateSomething();
    }
}

class Model {
    /** list of interested listeners (observers, same thing) */
    List<ModelListener> listeners = new ArrayList<ModelListener>();

    /** add a new ModelListener observer for this Model */
    public void addListener(ModelListener listener) {
        listeners.add(listener);
    }

    /** called internally when you need to tell the observer stuff changed */
    private void fireStuffChanged() {
        for (ModelListener listener : listeners) {
            listener.stuffChanged();
        }
    }

    /** method that results in a change in the model */
    public void updateSomething() …
KirkPatrick commented: Ezzaral had just taught me a bit of this and your comments helped me understand better what is going on, thanks bud. +1
BestJewSinceJC 700 Posting Maven

Well, you could have them do something like this:

String choice = JOptionPane.showMessageDialog(null, "Enter 1 for Small, 2 for Medium, 3 for Large, 4 for X");
int userChoice = Integer.parseInt(choice);
System.out.println("Your pizza price is " + sizePrice[userChoice-1]);

Honestly though, the other Dialog that I showed you before would be a much more reasonable dialog in this case, because it forces the user to pick from a list of choices, and the user can't pick anything that you don't want them to pick. The other dialog that I showed you returns an int which would represent '0' for small, '1' for medium, etc. So if you use that dialog, you could directly use sizePrice, whereas if you use the dialog that I showed you above, you have to do a bunch of extra work to make sure the user actually entered something between 1-4.

By the way, the code you posted above would work, except you cannot use '==' to compare two Objects for equality. Using '==' only works to compare primitive types (int, double, etc) for equality. To compare Objects for equality, you have to use a method - the equals() method. The equals() method is supposed to return true if the Objects are equal and false otherwise. So change this:


if (size == whatSize[s])
//Should be
if (size.equals(whatSize[s]))
BestJewSinceJC 700 Posting Maven

that only replaces the letter 'm' with '5' ... i need to increment it by 5 so it gives the letter
'r'. your code is not working

Yeah, but I already gave you the correct code to do this in post #4. . The same goes for the multiple explanations of toCharArray you were given. Obviously you don't want "help" you want the fully working code so I am done here. Good luck on your assignment.

BestJewSinceJC 700 Posting Maven

how do i convert a string to a char array??

In the first post of this thread I told you how to do that. Then I repeated myself, re-explaining what to do. Then Java Addict repeated my advice on using the toCharArray method again. Maybe you should pay attention to the advice you are given and actually try it out instead of expecting people to write code for you.

BestJewSinceJC 700 Posting Maven

Ok, I see. This link might be helpful. It'll use a dialog to drop down a box from which the user is forced to choose their option. So you could use the drop down box to force them to choose between S, M, L, X. They already have a code example there.

http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html#input

BestJewSinceJC 700 Posting Maven

Casting a char to an int is not advanced Java, it is basic. And I already gave you the exact code you need to use. In addition to that, all you need to complete your program is a few if statements and a for loop. Use Scanner to read in a String. Look at the example at the top that uses System.in as an argument to the Scanner constructor. You can use either the next() method or the nextLine() method; look at the method docs for those two methods.

P.S.

There is no beginner, intermediate, or expert section. We also don't do people's homework for them. At this point I think I've actually listed everything you need to know to do this problem. If you don't understand specifics of what I said I can help you, but research the topics yourself first.

BestJewSinceJC 700 Posting Maven

Not really man. Not trying to be rude but punctuation and clear explanations go a long way. I have no idea what 'pizza size' or anything else you mentioned has to do with your problem.

BestJewSinceJC 700 Posting Maven

Convert the char into an int. Figure out what range of ints represents the alphabet. (Just System.out.println() the int value) Then use if statements to make sure that you wrap around properly.

for (char start = 'a'; start < 'z'; start++){
System.out.println((int)start);
}
BestJewSinceJC 700 Posting Maven

Don't use Netbeans for dynamically generating panels. It only leads to frustration. Write your GUI by hand.

BestJewSinceJC 700 Posting Maven

Your explanation makes no sense. Do you want to know how to use a JOptionPane?

JOptionPane.showMessageDialog(null, "Here is some text!");
BestJewSinceJC 700 Posting Maven
char ch = 'a';
ch += 5;
System.out.println(ch);

As for everything else, I already told you everything else you need to know to do this. Like I said, yes you need a loop - you need a for loop. I'll give you one more hint: if you use toCharArray to put your String into an array of chars, then you can use a for loop to loop over each of the chars. So how will you know how long the array is? Use array.length

BestJewSinceJC 700 Posting Maven

Use the String class's toCharArray method. Then use a for loop to go through each character in the array. Decide whether or not to increment the character depending on whether or not it is a letter. You can figure out whether or not it is a letter with the Character class's isLetter method.

BestJewSinceJC 700 Posting Maven

The % or modulus operator gives, as its answer, the remainder after division. So 3 % 3 = 0 and 3 % 2 = 1 and 11 % 3 = 2

BestJewSinceJC 700 Posting Maven

This is the java forum. And you can use either Swing or SWT. Go read about them on google.

BestJewSinceJC 700 Posting Maven

im sorry im new to coding could you show me what you would do

Sure. I would read resources and examples on Java programming, especially on the topics that my assignment covered. Then I would think about how what I had learned applies to my current assignment. Then, if I was still having trouble, I would ask specific questions that demonstrated that I had made some effort.

BestJewSinceJC 700 Posting Maven

Are you using a JTextField? Then it would be textField.setText(someString); to set the text. Other than that, you haven't given nearly enough code for anyone to be of assistance..

BestJewSinceJC 700 Posting Maven

Isn't this the exact same question you had in this thread in the Java forum, where I gave you a very detailed explanation of what you needed to do? You never even replied back. Shame. Guess I wasn't very helpful.

BestJewSinceJC 700 Posting Maven

No problem. You might want to check out the contains() methods of the Rectangle class. They make it easier to detect which braille character you are clicking on.

BestJewSinceJC 700 Posting Maven

That's cool, it doesn't count anyway.

BestJewSinceJC 700 Posting Maven

No problem, mark the thread as solved

BestJewSinceJC 700 Posting Maven

Well, lets see your code.

edit:

And I also think, but am not positive, that in order to successfully write out the ArrayList, every Object that the ArrayList (directly or indirectly) contains must also implement Serializable except primitive types. So if you have ArrayList<Stuff> and Stuff has a DiffStuff inside it, then I *think* both Stuff and DiffStuff must implement Serializable and have unique IDs.

BestJewSinceJC 700 Posting Maven

Yeah; after you add the new widget to the JFrame, call myFrame.validate();

BestJewSinceJC 700 Posting Maven

I suppose you could try to draw different sized rectangles and other shapes then. But that's where you're on your own as far as me helping you, because I've only drawn on JPanels before.

If drawing on the buttons proves to be too hard, you could also draw your grid on a JPanel, implement MouseListener, detect the user's button clicks (using MouseListener) and detect whether or not you clicked on a particular button. I wrote code once that did exactly that, but the project is on my other laptop. If it comes to it, I can grab the project and give you an example.

BestJewSinceJC 700 Posting Maven

Don't be too upset by it, Mr. Ancient, sir.

BestJewSinceJC 700 Posting Maven

what are they focusing on ccna this time ??? i heard its about subbneting this time in the exam !! im planin to do it tomrw though ...let me know ...anyone anyone

It's purely focused on grammar. You don't stand a chance.

Ezzaral commented: hehe - I was thinking the same thing! +0
jonsca commented: 0 rep to counter your other 0 rep :) +0
BestJewSinceJC 700 Posting Maven

I don't see why not. But don't do that. Just add an image, it is much easier.

BestJewSinceJC 700 Posting Maven

If they aren't part of the same package then lets say you have a class called OtherClass in a package called other. Then you would need to add the following statement to the top of the class you wanted to use OtherClass from:

import other.OtherClass;

Then you would be able to do something like

//in some method:
OtherClass object = new OtherClass();
System.out.println(object.toString());
BestJewSinceJC 700 Posting Maven

Your example convinced me that the valueOf method completes faster; I'm not arguing with you on that. The linear time thing I was talking about is true, but isn't really that important - the main point I wanted to make is that in most cases, the choice of either valueOf or using the '+' operator is really up to the programmer, since either choice will not have a negative effect on the program's run time, as your program demonstrated. (It only took a couple hundred ms for a million operations... the average Java program probably does only a handful of String concatenations, with some exceptions)

BestJewSinceJC 700 Posting Maven

You have to declare each variable separately. Putting = new JPanel() at the end only declares the last variable, not all of them. Therefore your pnlUser variable has never been initialized with a "new" statement and is giving a NullPointerException.

BestJewSinceJC 700 Posting Maven

No problem, glad you got it working! Mark the thread as solved

BestJewSinceJC 700 Posting Maven

Is it not true that the queen isn't the one who has the most power? I live in the USA, but I believe the Prime Minister has more power than the Queen now a days. I'm posting this, because I don't understand the importance of who is queen, if the position isn't very powerful any more.

Yes that is true. If you want to know exactly what power the Queen has, use google.

BestJewSinceJC 700 Posting Maven

Then please ask your question in a separate thread. Yes it is possible and yes I know how to do it, but I just won't answer if you hijack 2 year old threads.