I am currently working on a java project, this involves me writing some code for a project, below are my attempts at coding so far:
/**
* Prints out details of all animal in the zoo.
*
*/
public void printAllAnimals() {
System.out.println("
Details for all animals in Zoo " + zooId);
System.out.println( "==================================");
[code]....
I currently cannot get the printallanimals() method to work as it should when executing the method printallanimals it just opens a filedialog box, when it is suppose to use the Collection object c,so that animals stored in the zoo can easily be checked.
I have to write a method called censor that gets an array of strings from the user as an argument and then returns an array of strings that contains all of the original strings in the same order except those with length of 4. For example if cat, dog, moose, lazy, with was entered, then it would return the exact same thing except for the words with and lazy.
Currently, my code so far just prints [Ljava.lang.String;@38cfdf and im stuck.
import java.util.Scanner; public class censorProgram { public static void main (String args[]){ Scanner input = new Scanner (System.in); System.out.println ("How many words would you like to enter?"); int lineOfText = input.nextInt();
[Code] ....
I have to make new string array in the method and return words without four letters in the main method
I am writing to a text file via user input and it is saving all the user input to the file but it is just printing one word per line. I would like it to print the string on one line and print the next string on the next line upon them hitting enter.
public void textFile() { Scanner reader = new Scanner(System.in); System.out.println("Enter file name: "); String fileName = reader.next(); File f = new File(fileName); PrintWriter p = null;
Okay so I have to write a method to compute the following series: m(i)= 1/3 + 2/5 +....+ (i / 2i+1) and write a test program that displays a table " i = m(i)" 1=0.3333 2=0.7333....all the way down to 20 which is 9.2480. I have written something and cannot seem to get the sum of the fractions to display .
public class ExtraCredit1 { public static void main(String[] args) { double num; double sum = 1;
I was writing a method to read a file. I did not think it through and gave the return type as void and modifier as static but I am not sure if it has to be void. How do you decide the return type of the method? Is there a good rule of thumb in such cases? Also, does the use of static needs to be done sparingly?
I had to write a class called Thermometer, that has one instance variable (an integer) for the temperature in Fahrenheit. I had to include the following methods
-a constructor that initializes the temperature to 60
-there is a method to change the temperature
-there is a method to display the temperature
-there is a method to reset the teperature to 60
Here is the code for that.
public class Thermometer { private int temp; private int thermometer; public Thermometer() { thermometer = 60;
[code]....
Now I get to the issue. I have to write a test class called thermometer to test the thermometer class. I need to test each method while displaying the temperature after it. My professor said I should use the invoke method but didn't go into much more detail than that.
The question is write to a method symmetric that accepts a stack of integers as a parameter and replaces the stack contents with itself plus a symmetrical version of itself (the same elements in the opposite order).
For example, suppose a variable s stores the following elements: bottom [10, 50, 19, 54, 30, 67] top
After a call of symmetric(s),the stack would store the following elements bottom [10, 50, 19, 54, 30, 67, 67, 30, 54, 19, 50, 10] top
Note that the symmetric version is added on to the top of what was originally in the stack. The bottom half of the stack contains the original numbers in the same order.
If your method is passed an empty stack, the result should be an empty stack. If your method is passed a null stack, your method should throw an IllegalArgumentException.
a) Write the method symmetric using one temporary stack and one temporary queue. /> Re-write the method using only one temporary Queue.
What I have done so far is
public static Stack symmetric(Stack s1){ Stack s2 =new Stack(); int theTop=0; if(s1.isEmpty()){ return s1;
I'm trying to write an indexOf() method that will return every time a value occurs in a linked list. I need to use my user-created linked list not the built in Java linked list. For example in a linked list of characters: "i, p, z, z, n, d, p, z" when I search for "z" it should return position variables for 3, 4, and 8. Currently what I have is obviously only returning the first instance.how I can return more than one instance?
public int indexOf(char input) { LLNode currentNode = this.first; int position =1; boolean found = false;
I have a java code that should sort an array of names based on the last name. e.g jane a, jane b, jane z, jane d should be jane a, jane b, jane d, jane z. I have the following code but for some reasons, the s1 in the comparator method is always null.
public class ShuffleName { public static void sortNames(String[] names){ Arrays.sort( names, new Comparator<String>() { public int compare( String s1, String s2 ) { String s1last = s1.split("s+")[1]; String s2last = s2.split("s+")[1]; return s1last.compareTo(s2last);
have to create a file named Lab13.txt. In the file I have 10 random numbers. I have to import the 10 numbers and have to Multiply all the numbers from Lab13.txt by 10 and save all the new numbers a new file named Lab13_scale.txt. so if the number 10 is in lab13.txt it prints 100 to Lab13_scale.txt. how do i get it to Multiply Here is what I have:
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++)
I'm doing this assignment in which i have to write some products in csv file...but as u can see in csv file two products are same "Cooking Oil"..so any method that can add two same product's quantity and their amount and write them in file
import java.util.*; import java.io.*; public class SalesbyTransactionMonth{ private static final String fileName = "Data.txt"; private static final String fileName1 = "sales_by_trans_month.csv"; String line = "";
I have a big problem with writing Gauss Elimination in Java code. This is my homework, it's true. But I want to learn this, and I don't know how to bite this. I must realise some points:
1) Create new class - Gauss Elimination with two attributes (table A (nxn) and table B with vector (n));
2) Add new method "eliminate" which transform matrix A and parametr vectors B ;
3) Add new method "solve" which calculate inverse substitution.
I tried to create a simple program. The main method is supposed to call out the secondary method to use Scanner in order to ask a person to type in a number, which will be assigned to int x. Then the secondary method supposed to return the int x to main method, which supposed to print it out. And for some reason I just can't do it. No matter what the main method refusing to accept the int x.
import java.util.Scanner; public class Return{ static Scanner newNum= new Scanner(System.in); public static void main(String[] args){ getInt(); System.out.println(x); } public static getInt( ) { // TODO Auto-generated method stub int x; System.out.print("give a num"); x= newNum.nextInt(); return x; }}
I am trying to create a method that takes an array of integers and prints it out using System.out.print. I'm having trouble creating the right way to print it out since I cannot find a way to convert the int array to a string to print it out.
public static String printArray(int[] num){ for (int i=0; i<num.length;i++){ String msg = num[i]; } return System.out.print(msg + " "); }
calculate how long it would take to pay off a loan of 500 pounds if there was 10% interest monthly, and 100 pounds was paid each month. This code is in a pseudocode,
set months = 1 set balance = 500 set totalpaid = 0; while balance > 100 balance = balance - 100; set interest = balance * 0.1 balance = balance + interest totalpaid = totalpaid + 100 months = months + 1 endwhile totalpaid = totalpaid+balance display "you paid "+totalpaid display "It took you "+months+" months"
I'm doing an assignment where a method receives a Queue as a parameter then convert it into a stack, I made it but now I want to try it in my main, but how can I do this? there's no toString and I cant use a for loop because I'm using a queue and not an array. This is the head of my method:
i have to write more than 100000 rows in a excel sheet (file size more than 20 MB) via java.
when i use XSSF, i am getting below Error.
java.lang.OutOfMemoryError: Java heap space at org.apache.xmlbeans.impl.store.Saver$TextSaver.resize(Saver.java:1592) at org.apache.xmlbeans.impl.store.Saver$TextSaver.preEmit(Saver.java:1223) at org.apache.xmlbeans.impl.store.Saver$TextSaver.emit(Saver.java:1144)
[Code]....
when i use HSSF , i am getting the below Error. java.lang.OutOfMemoryError: Java heap space
I have tried increasing the java heap size , by giving upto -Xms1500m -Xmx2048m
So I am trying to write the output of two different java class files to one txt file while the program runs. The file name is determined before the program is ran, through the command prompt as arguments. How can I get the second class file to edit the same txt file without running into compile errors.
For right now I'm just going to send everything that the second file outputs to a message String variable, so that the Main class outputs to the the text file. I still want to learn how to write to the same text file directly from the second class file.
import java.io.*; public class Test{ public static void main(String[] args) throws IOException{ int x; //create a new file internally called doc. But externally labelled the user input File doc = new File(args[0]); if (doc.exists()){
I have wrote the necessary program for the class which was : Modify the customer class to include changeStreet(), changeState(), and changeZip methods. Modify the account class to include a changeAddress() method that has street city and zip parameters. Modify the Bank application to test the changeAddress method.
The problem arose when I went to test it. For some reason when it asks "Would you like to modify your account information? (y/n)" it will not allow the user to input anything and thus test the class. Here is my code
Class Customer import java.util.*; import java.io.*; public class Customer { private String firstName, lastName, street, city,state, zip;
My issue is that when I run my search, it does find a goal. However, when I try and print the route using my print route method, it just gets stuck in a loop of printing the same two nodes. What is wrong with My A* implementation?
I am writing a program in the GUI Builder and found that when I add code to print user input from text fields to a text file, the main method is no longer recognized. It throws all kinds of errors.
I have been able to get the code to work separately in a project file. Also, have been able to print to the console.
I am trying out solving the question but i am stuck.The problem is to write a method that print data of single linked list backward using stack.The question is as follow
public class Stack{ public boolean isEmpty(){}; public void push(int n){}; public int peek(){}; public int pop(){}; }