I am making a java program that translates English into Pirate. I need working with the Word Pair class. I'm not sure what needs to be passed to the default constructor. And how to do the method that will take the words and pair them. here is my code and the dictionary file
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; public class PirateTranslator { public static void main(String[] args)
I have a project where I am required to read and write a vector of bank account objects and I am struggling with this concept. I was able to figure it out when the accounts were not stored in a vector but now that I am dealing with vectorsThis is my best attempt. Even though I know it's wrong, what I am trying to do.write/read methods in main:
public static void readTrans() { textArea.setText(""); chooseFile(1); try { FileInputStream fis = new FileInputStream(filename); ObjectInputStream in = new ObjectInputStream(fis); for (int index=0; index != fileIndex; index++)
What are the x- and y-coordinates of the Points referred to as p1, p2, and p3 after the following code executes? Give your answer as an x-y pair such as (0, 0). Recall that Points and other objects use reference semantics.
PHP Code:
Point p1 = new Point(); p1.x = 17; p1.y = 9; Point p2 = new Point(); p2.x = 4; p2.y = -1; Point p3 = p2; p1.translate(3, 1); p2.x = 50; p3.translate(-4, 5); mh_sh_highlight_all('php');
Create a class called DiceStatistics to represent a pair of dice and the totals of their rolls. It should have an array of two Dice as a private data member (these are the Dice from Problem 1). It should also have, as a data member, an array of integers to represent the possible totals of rolling two dice.
The class should also have the following methods:
initStats() to initialize all the totals to zero. rollOnce() to roll each die once, and add one to the correct totals element printStatistics() to print the number of times each total has come up over the number of runs.
Here is my code:
public class DiceStatistics { private final int NUMBER_OF_DICE = 2; private Dice[] dice = new Dice[NUMBER_OF_DICE]; private int[] totals; private int numberOfRolls;
[Code] ....
And here is the error:
run: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: Dice.roll at DiceStatistics.rollOnce(DiceStatistics.java:27) at DiceStatistics.main(DiceStatistics.java:55) Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)
I know it has something to do with the fact that I need to somehow import the information from my first program "Dice" into this in order to actually get the dice statistics, but how do I do that?
I have been having difficulty with the weeks concepts in my online Java class, the program is to be as followed:
For this exercise you will implement a class called Pair, that represents a pair of two numbers.The Pair class should include the following constructor and methods:
CONSTRUCTORS public Pair(double num1, double num2) -- Creates an object that represents a pair of double values
METHODS
public double getAverage() -- Returns the average value of the two numbers public double getDistance() -- Returns the absolute vale of the distance between the two numbers public double getMaximum() -- Returns the maximum value of the two numbers public double getMinimum() -- Returns the minimum vale of the two numbers
Write a class called PairTest that tests your Pair implementation. The PairTest should prompt the user for the two values, create a Pair object with the values and then print the average, distance, maximum, and minimum of the pair. The input / output should look like the following:
Enter the first number: 5.5 Enter the second number: 3.0
NOTE: For this exercise, your solution should not use any conditional statements. Instead you should use the methods provided by thejava.util.Math.
So far I have:
import java.lang.Math; import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner in = new Scanner(System.in); { System.out.println("Please enter a value for the first number");
I'm having some issues, trying to solve this problem in java. I want to print some election results, and i have to loop through a vector of objects and retrieve the partial sums of each party's seats for each constituency and the national results for each party. For now i can print the results per contituency, but i'm having problems in getting the national results. Like, adding the seats for labour party in Constituency A and B and C, etc, and print the sum. And do the same for conservative party.
This is what i have.
Java Code:
while (i < h.geral.size()) { show += "Constituency - " + ((Party) h.geral.elementAt(i)).getConstituency() + "
I understand how vectors work I'm currently using one to store my id's from my txt file but how do you put them in a defaultComboBoxModel?
DefaultComboBoxModel defaultComboBoxModel = new DefaultComboBoxModel(); //declare a vector object that will hold a string (only thing that works with comboboxmodel Vector<String> myVector=new Vector<String>(); //try statement try{ FileReader fr = new FileReader(file);
[Code]...
Any example of how a vector is used with a defaultComboBoxModel so I can then use that to populate my JComboBox?
When I input "the" or "and" I always receive "its not here" as the output. Why is this? I also tried printing the values of v.get(i).other and the system printed null twice.
public class Translator { public String other; public Translator(String x) { x = other;
I'm having extreme difficulty in working with a Vector storing a column with a BigDecimal value, and converting that single value into a float. I'm not sure why the code was written this way, but basically, I'm working with something called a vector that has a single Big Decimal value/column (not sure what the correct terminology is), and I want to store that value in a float variable called "dp". However, I don't know how to convert from the Big Decimal to a float.
Code is below:
String s = ""; sql = "SELECT DiscountPercentRate FROM Attendees WHERE AttendeeId=" + attendeeId; Vector v2 = sqldb.getResults(sql); /*I know that sqldb.getResults(sql) returns a vector with a single BigDecimal column of 15.0, in the test example I'm using*/ if (!v2.isEmpty()) { Vector data2 = (Vector)v2.elementAt(0); if (!data2.isEmpty())
[Code] .....
In case you're wondering what the sqldb.getResults() method looks, like, here's a snippet of it - There's an else statement that triggers in my case, adding a BigDecimal column to a vector, and returns that vector.
Vector v = new Vector(); ... else { BigDecimal bd = rs.getBigDecimal(i); vCols.add(bd); } v.add(vCols); ... return v;
How can I take the single result of my SQL query in that Vector/Big Decimal thing, and turn that result into a float value?
im trying to create an insertion sort method for a vector. I know how to insertionsort for an array, but for a vector im having problems
Source code: PHP Code: package test; import java.util.*; import java.io.*; public class LinearSearch { public static void main (String[] args) { Vector myVector = new Vector();
[Code]...
I'm getting errors at lines 38 and 39 "Left-hand side of an assignment must be a variable". "Syntax-error(s) on token(s) misplaces contructor(s)". How can i fix them ??
class GVector { // TODO: declare a private array to save the vector coordinates // Creates a mathematical vector of d dimensions, initialized at 0 public GVector(int d) { // TODO: implementation
[Code] ....
I'm confused with what type of array I need to use to save the vector coordinates and what to put in Gvector. Is it a constructor?
I'm playing with vectors for the first time... What I'm trying to do is to allow a user to input one or more integers and store them in a vector for manipulation later on in the program... Here's the portion of the program I'm working with:
Java Code:
package com.itse2317; import java.util.*; public class VectorTest { public static void main(String[] args) { Scanner input = new Scanner(System.in);
[code]...
My question is this: Is there any way to move from inputting integers to printing them, without entering a non-integer (for example, hitting enter)? I looked at the API for the Vector class, and either I'm not thinking about the problem the right way to be able to find an answer, or it's just not there.
I am running into some trouble with Line-Plane intersection, my method works, provided I am perpendicular to the plane I want to intersect. This is caused be the plane equation (with my given x, y, and z coordinates, the equation is -Z - 1 = 0). So the equation is only relying on the Z value of anything inputted. Is there another way to calculate the equation of a plane that would rely on all axis? Here is my current code:
Java Code:
Vector3f A = new Vector3f(0, 0, -1); Vector3f B = new Vector3f(0, 1, -1); Vector3f C = new Vector3f(1, 1, -1);
I have tried running the java application without adding the site to site list in java security tab. But I get a sand box message as APPLICATION BLOCKED BY SECURITY SETTINGS. How to run the java application without adding the site to site list in java security tab.
I want to develop a Java program that uses OpenScript APIs to test my applications. The OpenScript framework automatically creates the Java Code so I was thinking of either using this code or create my own using the APIs.
I tried both options using NetBeans but I'm getting errors everywhere starting with the library import. I'm pretty new to Java so I'm sure I'm missing a lot of things here. I pasted the code below from the OpenScript framework that want to use in a stand-alone file for your reference.,
I've written a java application with several classes all in the same .java file. It works just fine. Now, I've broken it up so that each class has its own .java file. Still works fine. My next step is to put those classes into a package, but I'm not about to get the program to run.The .java source files are all in /home/user/src
I've set the CLASSPATH to /home/user/src..All of the source files have "package com.myfirm.program" on the first line.I compiled the application with:
the compiler created the directory: /home/user/src/com/myfirm/program and put all of the .class files in there.So how do I get the program to run? if I run from /home/usr/src
java File1
I get: Exception in thread "main" java.lang.NoClassDefFoundError: File1 (wrong name: com/myfirm/program/Program)
In Main.java, How can i call method in CircleCalculationMethod.java ?
Should I put everything in same folder ??Should i do something like "import CircleCalculationMethod.java"Should i do something like create a package ...
The title of Question might seem old and previously asked.But I have a Question that what is difference between javaSE and Java EE.Although I knew what comes under JavaSE and What is under JavaEE.But My question is that.
What happens when we add PATH in our Environment Variable How does Eclipse or Other IDE use it?
Second Question is.
For Java SE we declare a Path Variable but for Java EE we do not add any library?(I know we add some jar file like for Servlet(Servlet-api.jar) and for EJB(Ejb.jar),But What is actaul difference?
I know about coding in general, Java, C, Python, SQL etc. but I barely know anything about making code come together on the web. I have a vague idea about what things like libraries and frameworks are,I'm interested in making a web application with which relies on Java do to the data processing. The idea is that the user inputs some messages, clicks submit, the text is taken away and processed, and the results are displayed on the screen. I would like the UI to be smooth with a modern look and feel.
Also, I usually do programming on Windows but I could also use Linux, so if I'll come across any specific drawbacks using Windows.