programming altogether and after almost reaching half way in the 'Head first java' book I decided to try and apply some of what I've learnt so far and write my first 'Object orientated' program. As this is pretty much the first program I've ever written, I decided to write a program to ask for two integers and add them both together and then present them to the user (the goal eventually being a basic fully working command line calculator with +,-,* and /. I'm expecting many compile errors but not the following errors below.
I have three .java files contained within a folder and after trying to figure out how to compile all three files (as they use one another) all at once, I came across this ---> javac *.java
so I typed this in the command line whilst in the directory containing the three files assuming *.java is the best approach and then I receive the following errors:
inputOutput.java:10: error: cannot find symb c.addition() = intIn.nextInteger(); ^ symbol: variable c location: class inputOutput
I'm writing basically my first program for school. I've written small ones, following instructions, but this is the most vague. I'm having issues. I can't figure out what the error means. I'm not done with the code, but I think the ArrayList is throwing me off. I'm trying to gather user input and sum the total. Here's the code:
package graduationplanner; import java.util.ArrayList; import java.util.Scanner; import java.lang.Double; public class GraduationPlanner { public static void main(String[] args) {
I keep getting the error Admit.java:10 cannot find symbol
import java.util.*; public class Admit { public static void main(String[] args) { sayIntro(); Scanner console = new Scanner(System.in); System.out.println("Information for applicant #1:"); getScore(console); getGPA(console);
[Code] ....
The compiler then reads:
Admit.java:10: error: cannot find symbol score1(ACTScore, SATScore, GPAScore); ^ symbol: variable ACTScore location: class Admit Admit.java:10: error: cannot find symbol
We are getting "Code too large" compilation error for one of our class. This class contains public String fields for label ID and value. We use this class for localization, except for English all other language labels come from .properties files.
The reason we are getting this error is because we have a static block in which using reflection we are populating a HashMap with all public fields and their value. The number of fields have gone up to the extinct where we are crossing the 64K limit for a static method. One of the most feasible solution was to use .properties files for English labels as well.
I will be calling this class MyLabels. We defined a super class for MyLabels called MyLabelsExt. And now we are adding labels into the super class instead of the MyLabels. By running some tests we confirmed that the map that we initialize in MyLables class contains all the fields from both MyLabels and MyLabelsExt class.
How is the 64K limit error not coming if the labels are defined in a super class. Does that mean Java is able to identify that some of the fields are coming from parent class, and that is being treated as separate from the child class. And how is the map that we initialize having all the value.
I have a msg object that contains an ArrayList<Integer> collection. However, in order to send the elements in the array over the udp socket, it needs to be sent as a byte[] array. So why am I using ArrayList<Integer> over byte array in first place? Well when I receive data from socket from embedded c program, I need to get an unsigned representation of the data, and thus I need to store it in integers, since bytes in Java are unsigned and unsigned chars in c that are greater than 127 will yield incorrect values in java. But when I send an ack back over the socket, I need to send the data back as bytes. So I convert the ArrayList<Integer> to a byte array:
Java Code: byte[] data = msg.toByteArray(); DatagramPacket response = new DatagramPacket(data, data.length, packet.getAddress(), packet.getPort()); public class Gprs { ... public byte[] toByteArray(){
[Code] ....
The problem is I get an "Cannot cast from Integer to byte" when trying to cast the integer to byte: data[i] = (byte)m_data.get(i);
This is likely a simple matter, but my error is confusing given the line it flags matches a working project I have. I get the following error on line 6 in the Controller:
cannot find symbol v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ...........................................^ (carrot at the J)
My view file:
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class View extends JFrame{ private JLabel lbl; private JButton btn;
This method accepts 1 integer, amount (the amount of money). Output the minimum number of in quarters, dimes, nickels and pennies used to make up the amount. For example, an amount of 32 would require 1 quarter, 1 nickel and 2 pennies.
This is the question^
My codes are:
public static int change (int amount) { int quarters = amount / 25 ; int firstresult = amount % 25 ; return quarters ; int nickel = firstresult / 5 ;
[Code] .....
The codes were working when i used System.out.println instead of return, but our teacher required us to use return (functions).
Netbeans do not detect any syntax errors, but I when I check the build it retuned areas they were a few; It's a simple program name 5 people, gade them then do final calulatoins it's called "grade tool.
heres the code
package gradingapplication; import java.util.Scanner; public class GradingApplication { public static double score(double score){ if(score >= 90){ System.out.println("A");
[code]...
~Problems~
1. It has no gui, I don't know java fx, is java groove used? awt is useful for creating spam bots in robot class, I know it's not very useful but it's so much fun.
class SubB{ public void foo(){ System.out.println(" x"); } } public class X extends SubB { public void foo() throws RuntimeException{ super.foo(); if(true) throw new RuntimeException(); System.out.println(" B"); } public static void main(String [] args){ new X().foo(); } }
Why the foo method of class X is not throwing a compile error because according to the override rule, if the superclass method has not declared exception, the subclass method can't declare a new exception...
I have a code in which I am reading input from System.in and Destination is some where else
Here is my code
File file=new File("D:/output.txt"); OutputStream os=new java.io.FileOutputStream(file); Scanner scanner=new Scanner(System.in); System.out.println("Enter Data to write on File"); String text=scanner.nextLine(); int c=Integer.parseInt(text); int a; while((a=c.read())!=-1) os.write(a); System.out.println("File Written is Successful");
In the line while((a=c.read())!=-1)
a compile time error is shown "cannot invoke read on primitive data type int"
I decided to code this quiz I took in class about asking the user to input a string and the code is suppose to check for upper case letters. If a upper case letter is found, it should increase a count by one. Once the check is done, it should display the number of uppercase letters. For some reason I am getting this weird compile error stating that symbols can't be found...
Java Code:
import java.util.*; import java.lang.*; public class StringCheck{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("please enter a string: " ); String s = input.nextLine();
In my code I read in a file of states and statecapitals then store them into a hashmap. I then ask the user what the capital is for the random state displayed.The problem I am having is getting the value for the random generated state. When I enter the correct capital for the state, it is still being marked incorrect. Here is my code.
Java Code: try {
Scanner scanner = new Scanner(file); String[] values;
Map<String,String> componentValueMap = new HashMap<String,String>(); Map<String,Map<String,String>> componentNameValueMap = new HashMap<String,Map<String,String>>();
I have for loop which are getting values from XML
XML structure as <Raj> <user>raj</user> <password>123</password> </Raj> <Dazy> <user>dazy</user> <password>123</password> </Dazy>
Now during first loop it will put user and password in map and after that put map refernce in another map. Same procedure for another values. But during iterating componentNameValueMap , i am getting Raj, Dazy as Key but not getting different values for them. I am getting latest values of Dazy in both Keys.
Because put method of Map<String,String> componentValueMap is replacing values. But I don't to replace them and want to get different values for different keys.
I am trying to retrieve a object from a hashMap not I am not sure what is wrong. I am trying to calculate if a car was speeding. They're 5 cameras and as they pass each camera I can calculate the speed. They key is camera number and I am sending in a Vehicle object.
Now I am trying to retrieve variables from the Vehicle so I can do the calculations. I am getting the error in the loop in void calculateSpeeding(). The loop is only for testing at the moment.
package online.practice.averageSpeed; import java.util.Arrays; import java.util.HashMap; public class Vehicle { String licensePlates;
I have a hashmap of the form HashMap <String, Set<String>>I am trying to create a method with one argument. The argument is a key for the hashmap, if it exists it should print out the key and the associated values. I'm falling over at even getting it to print the key, it keeps printing all the keys from within the hashmap as I don't know how to load the argument into it. I have this so far
Java Code:
public void printValue(String club) { boolean result = clubMap.containsKey(club); if (result) { String key = clubMap.keySet(club).toString(); System.out.println(key );
I am asked in my assignment to make a program that accepts a text file as an example a novel and i have to sort each word as a PERSON or ORGANIZATION or LOCATION or O as in Other , example :
Microsoft/ORGANIZATION ,/O Nelly/PERSON !/O '/O
Now we notice that microsoft is and organitzation and "," is Other and Nelly is a person's name and so on ..
Now I am asked to return the numbers of tags in the text which is 4 in our case because we have (ORGANIZATION,PERSON,LOCATION,OTHER)
My question here is my logic true ? And since i made a map of String,String ; Is there any way that i can get the size of the values in our case the values are the organization etc.. ?
I have one doubt.In HashMap if keys contains 1,2,3,4 and values are a,b,c,d we can get values using get(key) method like 1 will A,2 will return B and so on. Can we get the keys from values like A will get 1 and also if in key if there is a String like 1,2,3,Z and value is A,B,C,7 Z should get me 7. Here I am not using any generics.
I have a pretty large Hashmap (~250MB). Creating it takes about 50-55 seconds, so I decided to serialize it and save it to a file. Reading from the file takes about 16-17 seconds now.
The only problem is that lookups seems to be slower this way. I always thought that the hashmap is read from the file into the memory, so the performance should be the same compared to the case when I create the hashmap myself, right? Here is the code I am using to read the hashmap into a file:
File file = new File("omaha.ser"); FileInputStream f = new FileInputStream(file); ObjectInputStream s = new ObjectInputStream(new BufferedInputStream(f)); omahaMap = (HashMap<Long, Integer>) s.readObject(); s.close();
300 million lookups take about 3.1 seconds when I create the hashmap myself, and about 8.5 seconds when I read the hashmap from file.
SO my current code creates a graph with vertices and weighted edges. This data is stored in a hashmap. The key of the hashmap is the vertex and the value is a second hashmap. This second hashmap contains the edges with the vertex it connected to as the key and the weight as the value. My current problem is that when i try to remove vertices they are removed from the key set but they stay in the value(the second hashmap) as the key for that hashmap. IS THERE A WAY TO REMOVE THE VERTEX FROM THE KEYSET OF THE SECOND HASHMAP.
Code is as follows
constructor{ adjacencyMap = new HashMap<V, HashMap<V, Integer>>(); dataMap = new HashSet<V>(); } removal method{ if(dataMap.contains(vertex)){
my project flow is html,css,js<--->ajax<-->jsp<--->jdbc(.java)<--->mysql. In that jdbc i am returning the records from the database and fill into the resultset. From the resultset i put all records in arraylist and passed to jsp then i am displaying data in the screen.Whether i can use arraylist, hashmap or treetable?