Writing Print All Animals Method In Java

Aug 5, 2014

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.

View Replies


ADVERTISEMENT

Writing A Java Program To PRINT?

Oct 19, 2014

how to print from bluej onto actual paper? how to do the formatting and configuration etc.

View Replies View Related

Writing A Method That Returns Words Without Four Letters Back To Main Method

May 27, 2014

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

View Replies View Related

Writing To Text File - Print String On One Line

Oct 19, 2014

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;

[Code] ....

View Replies View Related

Writing A Method To Add Fractions

Apr 4, 2014

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;
 
[Code] ....

View Replies View Related

Writing A Method To Read A File

Jan 13, 2014

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?

View Replies View Related

Writing A Test Class Using (invoke) Method

May 4, 2015

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.

View Replies View Related

Writing Method Symmetric Using Stack And Queue

Apr 19, 2015

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;

[Code] .....

Its not working.

View Replies View Related

Writing IndexOf Method For More Than One Instance In A Linked List

Jun 7, 2014

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;

[code]...

View Replies View Related

Writing Java From Pseudocode

Nov 26, 2014

for x = 0 to 9
set stars = "*"
set count = 0
while count < x
stars = stars + "*"
count = count + 1
endwhile
display stars
endfor

I need to change this pseudocode to Java, but I'm new, been trying for ages but can't get it right.

View Replies View Related

Writing Own Custom Comparator In Java

Jul 27, 2014

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);

[code]....

View Replies View Related

Reading And Writing Files Into Java?

Apr 17, 2015

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:

Java Code: import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

[Code].....

View Replies View Related

Writing / Reading To And From Vector In JAVA

Nov 20, 2014

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++)

[code]....

View Replies View Related

File Handling In Java - Writing Objects In CSV

Dec 20, 2014

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 = "";

[Code] ....

Attached image(s)

View Replies View Related

Writing Gauss Elimination In Java Code

May 2, 2014

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.

View Replies View Related

Return Int X To Main Method And Print It Out

Oct 10, 2014

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;
}}

View Replies View Related

Creating Method To Print Array Of Integers

May 7, 2014

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 + " ");
}

View Replies View Related

How To Print Results Of Method To A File Using PrintWriter

Apr 29, 2015

private static void getTablas(int num) {
//ciclos anidados
System.out.print("x");
//linea horizontal
for (int i = 1; i <= num; i++) {
System.out.printf("%3d ",i);

[Code] .....

View Replies View Related

Calculate Time For Loan Payment - Writing Java From Pseudocode

Nov 26, 2014

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"

View Replies View Related

Method Receives Queue As Parameter - How To Print A Stack

Nov 4, 2014

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:

public static void QueueStack(Queue<Integer> q){

View Replies View Related

Java Heap Memory Error While Writing Large Data To Excel

Mar 6, 2014

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

View Replies View Related

Writing Output Of Two Different Java Class Files To One Txt File While Program Runs

Jul 20, 2013

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()){

[Code] .....

View Replies View Related

Print Statement Not Printing In Order To Call A Method From Another Class

Mar 17, 2015

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;

[Code] ....

View Replies View Related

Print Route Method / Stuck In A Loop Of Printing Same Two Nodes

Nov 13, 2014

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?

package search;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
 
[code]....

View Replies View Related

Netbeans 7.3 - When Adding Print Code Main Method Is Not Recognized

May 13, 2013

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.

View Replies View Related

Method That Print Data Of Single Linked List Backward Using Stack

Apr 23, 2015

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(){};
}

public class node{
int data;
node next;
}

public class list{
node first;
}

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved