What I'm doing about it: googling the shit out of my problems, consulting you fine readers, consulting my friends, and yesterday I signed up for Lynda.com. I'm hoping 30hrs+ or so of watching, rewatching, and analyzing the example code will catch me up before I get too behind in CS302
** Assignment Prompt **
Integer types are very convenient, but their limited width and precision makes them unsuitable for some applications where precision is more important than speed. Develop a class VeryLargeInteger that can handle arbitrary long integer numbers (both negative and positive) and the basic arith- metic operations (addition, subtraction, multiplication, division, and remainder).
Hint: The number could be represented as string, the sign could be represented either as boolean or as part of the string.
Note: Implementations of addition/subtraction through repeated use of a constant incremen- t/decrement will not be accepted. Implementations of multiplication and division that rely only on addition and subtraction will not be accepted.
I know I'm going to have to create a separate tester to call on the VeryLargeInteger class and it's math methods. For the new data type, should I convert the integer/string into an array in order to handle the large length of the number? I know he wants us to use recursion for the math methods. My gut tells me addition and subtraction will be slightly easier than multiplication and division. I know I'll have to reference the other methods for division. We aren't allowed to use the BigInteger class.
How I should construct any of the methods.
Java Code:
import java.util.ArrayList; /** ∗ VeryLargeInteger (VLI) is a class for arbitrary precision integer computation */ public class VeryLargeInteger { private int[] num1; private int[] num2; private int[] num3;
public class InputFileData { /** * @param inputFile a file giving the data for an electronic * equipment supplier’s product range * @return an array of product details * @throws IOException */ public static Product [] readProductDataFile(File inputFile) throws IOException{ // YOUR CODE HERE }
This code is meant to be used to read a text file and store the data in an array of type Product[]. I know how to read in a text file and have it sort it into an array, but I've never seen code laid out in this fashion before (specifically "public static Product[]", and I'm unsure how to work with "(File inputfile)". I've looked all over the place but can't find any examples of anything like this.
Also, the code given cannot be changed, as it's that code I have to work with.
I still don't understand how to use it as a whole. For example, do I read the file in the main and have this method read that in and output to the Product class? Do I read the file in this method? I can't work out how to make this work when I have to use this method.
I was trying to play around a little bit after learning creating multiple classes and stuff.However,i encountered a strange problem with reading a value from the user and then storing it in a variable.The usual way i do it is
But when i trying to print the contents of the variable "variableName" the compiler throws a lot of errors .I am attaching how i have tried that out in my code
import java.util.Scanner; class laptop{ private String modelNumber; private boolean hasFan; private float ramSpeed; protected int numCores; //private String input;
[code]....
Without the setInfo() in the laptop class the program functions as desired but i intend to ask the user if he wants to modify something and then reflect the same.
I need to create a JFrame with a user given amount of text fields in the form of a matrix. Say the user inputs 5 rows and 5 columns, I need to read those ints and create a 5 by 5 box of JTextFields in matrix form (i.e. 25 total text boxes in the form of a box). Here is some of the code I have been trying to use to do this...
int x = 10; int y = 10; for(int i = 0; i<rowSize; i++){ y= y+40; for(int k =0; k<colSize; k++) { newField = new JTextField("0"); newField.setBounds(x,y,40,20); win2.add(newField,0); win2.repaint(); x= x+60; } }
In order to go through the loop a given amount of times and create that amount of text fields in the correct places.Am I even close to doing this right?? Cuz I can't get the text fields to even show up on my window.
The objective of the code is to add new records based on existing records with a partial change to the key. I'm getting "type of the expression must be an array type but it resolved to DstidArray" on dsTidRecTbl[i]
String stMajor = request.getParameter("stMajorVersion"); String stMinor = request.getParameter("stMinorVersion"); String stPatch = request.getParameter("stPatchVersion"); StringBuffer stKeySB = new StringBuffer(stMajor+stMinor+stPatch); String stKey = new String(stKeySB.toString()); DstidArray dsTidRecTbl = new DstidArray(stKey); request.setAttribute("dsTidRecTbl", dsTidRecTbl);
I have to write a short quiz that consists of 3 multiple choice questions. When the question is answered wrong I have to get it to loop back and ask the same question until the question is answered right.
I think I have the majority of my variables assigned and I have the scanner set up.
System.out.println("Question 1- Which TV sitcom recently had it's 20th anniversary?"); System.out.println("1. Two and a half men " + question1 + ".Friends 3.The Fresh Prince of Belair h.Get a hint"); answer2 = stdIn.nextInt(); if (answer2 != question1) { System.out.println("Your answer was incorrect, please try again or pick h for a hint"); } else { }
I have the following code in which I am looping through the rows of one array (composed of Strings) and copying it to another array. I am using .clone() to achieve this and it seems work as it changes the memory location of the rows themselves. I did notice that the String objects are still pointing to the same location in memory in both arrays but I won't worry about that for now, at the moment I just want to understand why the array I am cloning is not successfully assigning to the other array.
This is the incorrect line: ar[r] = maze[r].clone();
I am working on a problem where i have to create a 2d array with given input of the dimensions (odd number) of array, along with a number within the array and to then print out all of the numbers surrounding that number.
Anyway, i am working on simply making the spiral, which should look like the one below.
n = 3
7 8 9 6 1 2 5 4 3
where the 1 always starts in the center with the 2 going to the right, 3 down, then left etc. etc. I was able to create the code by starting on the outer edges rather than the center and working my way to the middle, however my code always starts from the top left and goes around to the center where it needs to start from the top right. I am having trouble altering my code to meet this criteria. This is what i have thus far.
import java.io.*; public class Spiral { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the number of elements : "); int n=Integer.parseInt(br.readLine());
While practicing java i have came across boolean data type. i have executed below program but i am not sure how i got output of the program like below:
10 > 9 is true
Here is my program:
class BoolTest3 { public static void main(String args[]) { System.out.println("10 > 9 is "+(10>9)); } }
My question is: how this program will come to know that 10>9 true or false.. how bolean data type used in this program.
I am totally new to Java. What is the purpose of this method?
Flow of the int x=3; like where does the 3 go step by step?
Passing Primitive Data Type Arguments (from oracle java tutorials)
Primitive arguments, such as an int or a double, are passed into methods by value. This means that any changes to the values of the parameters exist only within the scope of the method. When the method returns, the parameters are gone and any changes to them are lost. Here is an example:
public class PassPrimitiveByValue { public static void main(String[] args) { int x = 3; // invoke passMethod() with // x as argument passMethod(x);
I was struggling to use BufferedReader to extract some data and then perform some calculations and then have the results as outputs.
I haven't quite solved that issue but in order to progress, I hard coded some values into my application and proceeded with the actual calculation loops etc.
Currently, the value out put from one of my calculations is given as:
1.1704926E7
How can I make the console show it in a natural way. I've performed the calculation manually and it should be 11704926.5 I don't want to lose that .5!
Primitive arguments, such as an int or a double, are passed into methods by value. This means that any changes to the values of the parameters exist only within the scope of the method. When the method returns, the parameters are gone and any changes to them are lost.
Reference data type parameters, such as objects, are also passed into methods by value. This means that when the method returns, the passed-in reference still references the same object as before. However, the values of the object's fields can be changed in the method, if they have the proper access level.For example, consider a method in an arbitrary class that moves Circle objects:
public void moveCircle(Circle circle, int deltaX, int deltaY) { // code to move origin of // circle to x+deltaX, y+deltaY circle.setX(circle.getX() + deltaX); circle.setY(circle.getY() + deltaY);
// code to assign a new // reference to circle circle = new Circle(0, 0); }
Let the method be invoked with these arguments: moveCircle(myCircle, 23, 56)
Inside the method, circle initially refers to myCircle. The method changes the x and y coordinates of the object that circle references (i.e., myCircle) by 23 and 56, respectively. These changes will persist when the method returns. Then circle is assigned a reference to a new Circle object with x = y = 0. This reassignment has no permanence, however, because the reference was passed in by value and cannot change. Within the method, the object pointed to by circle has changed, but, when the method returns, myCircle still references the same Circle object as before the method was called.
I am trying to use double data type in a for loop for precise operations and just to see if there could be any problem doing that I tested a small code :
public class doubleLimit { public static void main(String[] args){ for(double i=-0.1;i<=0;i+=0.01) System.out.println(i); }}
The output I was expecting is : -0.1 -0.09 -0.08 -0.07 -0.06 -0.05 -0.04 -0.03 -0.02 -0.01 0.00
But the output of the code is : -0.1 -0.09000000000000001 -0.08000000000000002 -0.07000000000000002 -0.06000000000000002 -0.05000000000000002 -0.040000000000000015 -0.030000000000000013 -0.02000000000000001 -0.01000000000000001 -1.0408340855860843E-17
Why is the code not working the way I expected, I think it has something to do with any property of double but I am not sure.
Is this the proper way to add to a generic list? My code works just fine, but I got this feeling that there might be some kind of flaw in it or something. Is this pretty much the basic way to add any type of data to a generic list?
import java.util.LinkedList; public class ListOfGeneric<E> { private LinkedList<E> myList;
I'm creating a small program that will be able to chart data that will be transmitted from a sensor device connected to the USB port. I would like to create a running chart that will display the data sequentially with respect to time.
[URL] ....
I am not sure how to implement the runLater function and display the data. What should I hope to accomplish using the ranLater function? I understand that I need to an XYChart.Series to keep a continuously modifying chart, but other than that I'm not sure how to implement it.
There are multiple .CSV files (each file has multiple rows and columns). I need to fetch data from all the files and find MEDIAN of the values for each column and do further calculations. Suppose there are 3 files, i need to find the MEDIAN of column 1 in file1, MEDIAN of column 1 in file2, MEDIAN of column 1 in file3. Below code just fetch data from one file.
In my project i am facing an problem, The My SQL Data base will accept the date format of yyyy/mm/dd only as "Date" data type but in my program i wants to use dd/mm/yyyy format. (i have this same format now) that's why I am unable to insert / retrieve it..
I'd like to create my own Table Model to handle data from an SQLite database using JSwing, but I'm having difficulty. How to confirm the following:
-- A table model is an object that contains methods for manipulating data in the table, right?
If that's the case, then how should I create a Table Model to handle data coming from a database. From what I understand...
My custom Table Model needs to subclass AbstractTableModelI then override 3 methods from AbstractTableModel (getRowCount(), getColumnCount(), getValueAt())
As it relates to drawing data from a database, how should I be thinking about this problem (i.e. creating a Table Model that can work with a database)?