No one has voted on any posts yet. Votes from other community members are used to determine a member's reputation amongst their peers.
44 Posted Topics
hi guys, I'm new to python and i can't seem to understand this one line of code right here: distance, coordinates = min([(someFunction(state, coordinates), coordinates) for coordinates in coordinatesList]) coordinatesList contains a list of paired coordinates (x,y). someFunction returns an int. My question is why isn't distance and coordinates contain … | |
Ok i've just starting learning css and html and i created a nav bar following a tutorial. HTML file--------------------- <div id = "wrapper"> <div id = "navmenu"> <ul> <li><a href="#">ITEM</a> <ul> <li> <a href = "#">items</a> </li> </ul> </li> </ul> <ul> <li><a href="#">ITEM</a> <ul> <li> <a href = "#">item</a> </li> … | |
public class QS { public static <T extends Comparable<? super T>> T[] quickSort(T[]array) { return doSort(array, 0, array.length - 1); } //some other methods................. public static void main(String [] args){ QS qs = new QS(); int [] nums = {4,7,23,1,2,45,23,11}; qs.quickSort(nums);//gives error } } I am getting an error in … | |
So i have a class that takes 2 generics types: public class Something<K,V>.... In another class, i'm trying to create an array of Something objects. how do i do this? i'm getting an error with this: Something <K,V>[] s = (K,V[]) new Object[size]; | |
serious noob question, but i'm following my android book and it is doing something with a class that extends list activity. is that a file that i have to create on my own, or is that provided once i create a new android project? i can't seem to find it. | |
i have a private Node class with a getValue() method that returns the Node's value which is of generic type. In another class i've tried doing this: T tempItem = null; ----also generic tempItem = currentNode.getValue(); I get a complier error unless I cast it like this: tempItem = (T) … | |
Re: [CODE]While(true){ Number/2; If(condition) break; } [/CODE] | |
my program includes pictures and audio, do i have add that to my project and then create a jar file? or i just have to include the source file and that's it? | |
i'm trying to write a game that show a background and a player on screen simultaneously using 2 different classes. here are the relevant parts of the program, or at least i think [code]public WorkingTitle2(){ super("Working Title"); setSize(550,429); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); loadPictures(); loadSounds(); pp = new PaintP(); pb = new PaintB(); add(pb); … | |
i've made this little game but the image keeps on flickering. i've read about double buffering online, but i really don't know how to implement the code into my game. here's some of the source code from the constructor and paint method: [code] public Game(){ super("test"); setSize(495,429); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); try{ … | |
i am not saying that all of my jar files are not working. in fact, all of them do work so far except for this one game that i've made. it runs perfectly in my editor, but its jar file will not execute. i checked its MANIFEST.mf file and the … | |
i don't know what happened, but i was running an applet that i made on a webpage and it works fine. i have the latest JRE and i am running firefox 4. then i've made some changes to the applet, tested it, it works, and copy and paste the class … | |
[CODE]if(count == 4){ qFinal.enqueue(q.peek()); if(count3 == 0){ System.out.println(qFinal); break; } else{ sort(qFinal); } } [/CODE] this code is inside a while loop, and with the break statement, it should break out of the loop right? instead i think the program also executes the sort(qFinal) method b/c after it prints qFinal … | |
i am getting an error in this. basically it sorts a queue in abc order. [CODE]public class Queue2{ public static void main(String [] args){ LinkedQueue q = new LinkedQueue(); q.enqueue("d"); q.enqueue("v"); q.enqueue("b"); q.enqueue("a"); q.enqueue("d"); System.out.println(q); System.out.println("----------------"); sort(q); } public static void sort(LinkedQueue q){ LinkedQueue qFinal = new LinkedQueue(); int count … | |
this is a linked list based queue private class Node { String value; Node next; Node(String val, Node n) { value = val; next = n; } } public String dequeue() { if (empty()) throw new EmptyQueueException(); else { String value = front.value; front = front.next; if (front == null) … | |
this assignment has stomped me. i thought it about long and hard and can't imagine how would i edit the quicksort to sort an array-based queue object. i'm required to use an array-based queue class which has only 3 methods: enqueue(), dequeue(), and peek(). they're pretty self explanatory. i cannot … | |
ok i have this assignment which i'm just having problems with the iterator part of it. from the [B]ListType [/B]class, this is what i wrote: [CODE] public Iterator iterator(){ return new OrderedStringListTypeIterator(list); } [/CODE] this code is from the textbook which idk how they got theirs to work, but... [CODE]import … | |
[CODE]public static void fun(int x){ System.out.println(x); x--; if(x > 0){ fun(x); } System.out.println("returning " + x); } [/CODE] in the main class: fun(5); [U]output:[/U] 5 4 3 2 1 returning 0 returning 1 returning 2 returning 3 returning 4 --------------------------------------- what i don't get is how the print statement is … | |
ok i got this assignment, and i'm a bit confused about what this method is supposed to do. i have to create a "setLab" method and accept a Grade object (which is already done and provided). this is what i got so far: [CODE]public class CourseGrades{ private Grade [] grades … | |
ok so the program gets a list of numbers, and it counts how many times a number is entered. [CODE]for(int i = 0; i < numList.size(); i++){ for(int j = numList.size() - 1; j > i; j--){ if(numList.get(i) == numList.get(j)){ count++; numList.remove(j); } } System.out.println(numList.get(i) +" " + count); count … | |
[CODE] vowels = wordcount.vowelNum(); //counts the vowels consonants = wordcount.consNum(); //counts the consonants, this is not working properly. [/CODE] the consNum() method: [CODE] int length = word.length(); for(int i = 0; i < length; i++){ if(word.charAt(i) == 'a' || word.charAt(i) == 'u'|| word.charAt(i) == 'i'|| word.charAt(i) == 'e'|| word.charAt(i) == … | |
[CODE]for(int i = 0; i < floorNum; i++){ if(floorNum == 12){ continue; { statements; statements; statements; }[/CODE] ------------------- if there anything wrong with this statement? i've tried using a while loop and the continue statement would work and skip number 12, but this doesn't work. | |
this program just prints out prime number within the range of the for loop. however it doesn't print anything. [CODE] boolean prime; for(int i = 11; i < 100; i++){ prime = isPrime(i); //this method works as i tested it before if(prime){ System.out.println(i); } } [/CODE] everytime i run this … | |
Re: [CODE]double [] salary = new double [4]; salary[0] = 1550.8; salary[1] = 2439.5; salary[2] = 1800.75; salary[3] = 2890.0; //show the array before the bonus// for(int i = 0; i < 4; i++){ System.out.println(salary[i]); } System.out.println("----- with bonus-------"); double bonus = 0; for(int i = 0; i<4; i++){ bonus = … | |
[CODE]System.out.println("what is your name? "); String name = kb.nextLine(); for(int i = 0; i < member2.size(); i++){ if(member2.get(i).equals(name)){ System.out.println(name + " is a member. "); break; } else{ System.out.println(name +" is not a member. "); break; } [/CODE] i did a system.out.println on the member2 arraylist (String arraylist) and it … | |
for example, i have a txt file that reads: number of items: 2 number of zombies: 3 .... i want to write a method that increments just the numbers, and leave the "number of items" and "number of zombies" alone. is there any way to do this? i can easily … | |
[CODE]else if(choice == 3){ System.out.println("what is your name? "); String name = kb.nextLine(); boolean x = Member.checkMember(name); System.out.println(x); } [/CODE] when i run this, it prints "what is your name?" and instead of waiting for me type in something, it just skips that part and go ahead and prints x. … | |
i wrote a program that calculates how many coins that a vending machine splits out and such, and it does work but i can't figure how it works. at the time, i was sure of the logic, but now i can't understand how this is possible. [CODE] change = (amountPaid … | |
[CODE]public static String strCap(String str){ //capitalizes the first letter of the string String newStr1 = str.replace(str.charAt(0), Character.toUpperCase(str.charAt(0))); int position = str.indexOf(". "); // looks for a period followed by a space while(position != -1){ newStr1 = newStr1.replace(newStr1.charAt(position + 2), Character.toUpperCase(newStr1.charAt(position + 2))); position = str.indexOf(". ", position+1); } return newStr1; … | |
here is some code from one class... [CODE]public boolean ticketStatus(){ if (fine > 0){ status = true; } else{ status = false; } return status; } [/CODE] and this is from another class... [CODE]public void getTicket(){ if (parkingticket.ticketStatus()){ toString(); } else{ System.out.println("you do not have a ticket. "); } } … | |
[CODE]public double returnTotalFine(){ if (parkingmeter.returnPurchasedMins() >= parkedcar.returnMinsParked()){ fine = 0; } else if (parkingmeter.returnPurchasedMins() - parkedcar.returnMinsParked() <= 60){ fine = 25; } else{ fine = (25 + (10 * (parkedcar.returnMinsParked() / 60.0))); } return fine; } [/CODE] this is the toString method from the same class as above: [CODE]public String … | |
[CODE] String[] names = new String[namesListSet.size()]; int[] nums = new int[namestimesSet.size()]; namesListSet.toArray(names); [B]namestimesSet.toArray(nums);[/B] for (String s : names) { System.out.print(s); } [/CODE] i'm getting an error on the bold part. getting symbol not found. | |
[CODE] String names1 = ""; System.out.println("enter names: "); names1 = kb.next(); while (names1 != "stop") { System.out.println("enter names: "); names1 = kb.next(); namesList.add(names1); } [/CODE] everytime i type "stop," the program keeps running... | |
[CODE] int [] wronglist = new int [incorrect]; for (int i = 0; i < 6; i++){ for (int j = 0; j < i; j++){ if (studentArray[i] != ansArray[i]) wronglist[i] = (j+1); [/CODE] ok i'm trying to write a program that figures out what number did the user got … | |
[CODE]public static int totalCorrect(String [] studentArray, String [] ansArray){ int numCorrect = 0; for (int i = 0; i < 6; i++){ if (studentArray[i] == ansArray[i]) numCorrect += 1; } return numCorrect; } [/CODE] instead of returning the actual number, it always return 0. here is the whole program: [CODE]import … | |
[CODE]import java.util.Scanner; public class Highest{ public static void main (String [] args){ Scanner kb = new Scanner(System.in); int scores [] = new int[3]; String names [] = new String [3]; int highest = scores [0]; String names1 = names [0]; for (int i = 0; i<3; i++){ System.out.println("enter name and … | |
[CODE]double wholeCost = kb.nextDouble(); double markupPercent = kb.nextDouble(); double markup = markupPercent/100.0; double retailT = calculateRetail(wholeCost, markup); System.out.println(retailT); public static double calculateRetail(double num1, double num2){ double markupPrice = ((num1 * num2)+ num1); return markupPrice;} [/CODE] i've been staring at this and can't figure what is wrong with it. the compiler … | |
[CODE]import java.util.Scanner; public class Inti{ public static void main (String [] args){ Scanner kb = new Scanner(System.in); System.out.println("enter name: "); String input = kb.nextLine(); char name1 = input.charAt(0); int blank = input.indexOf(' '+1); char name2 = input.charAt(blank); int lastBlank = input.lastIndexOf(' '+1); char name3 = input.charAt(lastBlank); System.out.println(name1 + "\n" + … | |
particularly from a txt file. for example if the file reads "name ###-####-#### address" all in one single line. how do i put all three items in three separate variables and print them? | |
ok i need to write something like [CODE] if { days > 5 && minutes > 5 } [/CODE] basically i need minutes to be around 5 to 10, and cannot be greater than 10. how do i do write this within the same if statement? | |
ok i am writing a program that ask for the amount total and amount tender. then i'm supposed to calculate a combined amount of coins and dollars to make up the change amount. i know how to split out the dollar amount, but i'm stuck on how to calculate the … | |
ok i'm tryiing to convert a double into a string to get the 1st character of that number. [CODE] change = (amountPaid - total); String dollars = Double.toString(change); String firstNum = dollars.charAt(0); [/CODE] i got an imcompatiable type error on that part. change, amountPaid, total are double. | |
[CODE]import wx class bucky(wx.Frame): def __init__(self,parent,id): wx.Frame.__init__(self,parent,id,'Frame aka window', size=(400,300)) panel=wx.Panel(self) status=self.CreateStatusBar() menubar=wx.MenuBar() first=wx.Menu() second=wx.Menu() first.Append(wx.NewId(),"new window") first.Append(wx.NewId(),"Open...") menubar.Append(first,"File") menubar.Append(second,"edit") self.SetMenuBar(menubar) if __name__=='__main__': app=wx.PySimpleApp() Frame=bucky(parent=None, id=-1) Frame.Show() app.MainLoop() [/CODE] when i run this program, i get a "self is not defined in status=self.CreateStatusBar()". so i erased that part, and it … |
The End.