ASCII File - Passing Array As Parameter?

Feb 23, 2014

I am trying to make a class definition file for an ASCII File.

Ultimately, I want to be able to add methods to allow the image produced by the file to be printed normally, then printed with various manipulations.

However, for some reason, whenever I try to run the program to test my normalPrint method, it terminates without printing anything.

I think this is because the array's values width and height are not within the scope of the method. I tried passing the array as a parameter for the method like so:

Java Code:

public void normalPrint(char [][] poop){
//method here
} mh_sh_highlight_all('java');

But it gave me an error that stated

"The method normalPrint(char[][]) in the type asciiFile is not applicable for the arguments ()"

Class Definition:

Java Code:

import java.io.*;
import java.util.Scanner;
public class asciiFile {
int height;
int width;

[Code] .....

View Replies


ADVERTISEMENT

JSP :: Passing Parameter To Imported File

May 14, 2014

I am trying to run an example in which I pass a parameter to imported file but its not working.

This is my header.jspf file which I will include in a jsp file.

<img >
<br>${param.sub}

And This is the JSP file contact.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
<c:import url="header.jspf">
<c:param name="sub" value="We love to hear from our clients------------" />
</c:import>
<br><br>

Now this is JSP page content

</body>
</html>

When I hit the contact.jsp file , It does show me the image I have on header.jspf , but its not able to print the parameter that I am setting in <c:param>

So after showing image it just shows ${param.sub}. So EL is not translated properly.

View Replies View Related

Passing A Map As Parameter

Apr 30, 2014

I'm using Java in BlueJ where I'm trying to write a class to store cycling club membership details in a map. I'm trying to pass a map as a parameter to a function that will iterate over the map and print out the member details. My code is:

public class CtcMembers
{
//instance variables
private Map<String, Set<String>> memberMap;
/**
* Constructor for objects of class CtcMembers

[Code] ....

When I execute the following in the OU workspace:

CtcMembers c = new CtcMembers();
c.addCyclists();

I can see a map populated with the expected details.

When I execute the following in the OU workspace:

c.printMap(c.getMap());

I get the following error:

java.lang.ClassCastException: java.util.HashSet cannot be cast to java.lang.String
in CtcMembers.printMap(CtcMembers.java:81)
in (OUWorkspace:1)

I wasn't aware I was trying to cast anything so this has got me baffled.

View Replies View Related

Passing Object As Parameter?

Aug 8, 2014

i want to pass an object of type Software to assign it to a computer from Computer class...

i should note that computer and software are arrays of objects thats the variable and method to set software in Computer class

private Software[] software;
public void setSoftware(Software software,int index){
this.software[index]=software;}

note: the user choses the a computer from a list and a software as will

for example the program will show the user 2 computers

0 for computer: apple, Model: mac mini, Speed: 2.8

1 for computer: sony, Model: vaio, Speed: 2.2

the user enters the index he wants then the program will show a list of software to add to the computer selected

the error I'm having is run time error Exception in thread "main" java.lang.NullPointerException and it points to these 2 lines

1.comp[Cch].setSoftware(software,Sch);

2. the method setSoftware

every thing is running correctly but this step above

Cch= the chosen computer index

Sch= the chosen Software index

why am i getting an error and how to fix it?

View Replies View Related

Try Catch Passing Parameter

Oct 15, 2014

I'm asking if there is a way to pass parameter between try/catch block.

I have a method:
 
public void invia(OiStorto invioaca) throws Exception {      
         Long id=0L;
        try {
               //some code
     for (VElenpere elenpere : elenperes) {

[Code] ...

The method called in the for:

private void popolaScompiute(Long anno, InviaEOI inviaEOI0, _4IntegerType param, ElOpeIncType opereIncompiute,
            VElencoOpere elencoOpere,Long id) { 
        try {
          //some code
     for (OiOpera opere : oiOpere){
             
[Code] ....
   
And finally the method in which the error can occur (the method poputa is called for every id)
 
private void poputa(ElOpeIncType opereIncompiute, OpeIncType operaSingola, OiOpera opere) {
try {
//some code
} catch (NullPointerException e) {
            e.printStackTrace();
            //return id;
        }
       
So method invia call the method popolaScompiute, inside popolaScompiute there is an iteration through some id and for some id can occur an error; what i want is the getting the value of id in the first method invia, using the block try/catch. Is there a way to accomplish this?

View Replies View Related

Passing A Boolean Parameter From One Method To Other

Jan 30, 2015

Java SE Runtime Environment build 1.8.0..This is part of the code:

public static int addAddress (String[] number, boolean[] front, double[] total) {
int num = 0;
double ffee = 0;
/*boolean value = false;*/
 
[code]...

I have tried using the line of code commented out, /*boolean value = false;*/. However, another error is displayed. The compiler shows the following...

Inspection.java:33: error: incompatible types: boolean cannot be converted to boolean[]
front[num]= defineFront(num, value);
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output error...I know that boolean values are by default stored as false, once you create the array. However, I'm having trouble passing the variable to the method.

View Replies View Related

Passing Object As Parameter - Combination Values Are All Zero

Mar 8, 2015

I have an object that has an instance of another object class as its parameter :

CombinationLock oneHundred = new CombinationLock(28,17,39);
Locker Mickey = new Locker(100, "Mickey", 3, oneHundred);

This is for a locker, which has a combination assigned to the student. Within the locker class I have the following constructor:

public Locker(int locker, String student, int numberOfBooks, CombinationLock combo) {
this.locker = locker;
this.combo = combo;
this.student = student;
this.numberOfBooks = numberOfBooks;
}

combo is the private CombinationLocker object I created within the Locker class. Do I need to pass the combo object on to the CombinationLock class? For reason, I do not comprehend, the combination password from the main class is not passing through to the CombinationLock class, and the combination values are all zero.

View Replies View Related

Read ASCII Art Map And Store Information In 2D Array

Feb 12, 2014

I've written some code to do this, but it's not working as I expect. This is what the ASCII map looks like:

###################
#.................#
#......G........E.#
#.................#
#..E..............#
#..........G......#
#.................#
#.................#
###################

Here's how I've tried to store the information in a 2D array:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
 public class Map {
 public void importMap() throws IOException{
BufferedReader br = new BufferedReader(new FileReader("map.txt"));
String line;

[Code] ....

But it's not printing out what I'm expecting. It's printing out:

[[#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [

What is printed is much larger than what I've copy and pasted but I can't post it all here.

The error I get is:

Exception in thread "main" java.io.IOException: Stream closed
at java.io.BufferedReader.ensureOpen(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at Map.importMap(Map.java:26)
at Map.main(Map.java:44)

View Replies View Related

Passing More Than One Array In A Method?

Nov 3, 2014

Can we pass more than one array in a method?

View Replies View Related

Parametrized Array Type As Method Parameter?

Jul 31, 2014

I have the following method:

public static void doSomething(List<? extends GenericClass> input)
{
// op
}

^

This compiles and works, ensuring I can only pass in a List of a type extending GenericClass.But now I want it to accept an Array instead of List. This is where I'm stuck:

public static void doSomething(<? extends GenericClass>[] input)
{
// op
}

^

A wrong guess at the syntax which does not compile. One solution is to convert Array into ArrayList before calling the 1st method above, but I'd rather bypass this if possible.

View Replies View Related

Parse Value Of Array Of Object Passed Through A Parameter

Oct 29, 2014

I'm working on a method that would parse the value of the array of object that I passed through a parameter. I would like to ask if making Object as a parameter is doable. Let's say I have a class Student and Teacher. I created a class the would handle the sched and name it class Schedule and extend this class to the Student and Teacher. Now I want to have a function that will accept an array of Schedule from either Student and Teacher, what ever object I will pass in the parameter. I know its easy to just make a method with a separate parameter of my classes but im looking for a more dynamic code.

class Student extends Schedule{
//variables here for student
}
[code]

class Teacher extends Schedule{
//variables here for teacher
}
[/code]

private void parseObject(ArrayList<Object> objct){
Schedule temp = objct.get(0);
//there is no error in this part

}

Now when i will try to use the function and pass a data, it will not accept since my parameter should be an array of object. How would I twist dis one?

ArrayList<Student> temp_student = new Array....
parseObject(temp_student); // it will not accept my parameter, how would i make it as an object

View Replies View Related

JSP :: Resource File Parameter Value?

Mar 11, 2015

I have a entry in application.properties file

caption_bubble_value.title={0} is a caption for the element box

JSP File

<fmt:message key="caption_bubble_value.title" />

in the java file I am setting a parameter to session

request.getSession().setAttribute("replaceVal", "Value headline");

How can I get the text "Value headline is a caption for the element box" on the page?

The replacement should happen on an event.

View Replies View Related

Passing Array As Cmd Line Argument

Mar 10, 2014

Can we pass array as a cmd line argument as follows ?

>java TestRun file[], number
if yes, in the main(), how do we capture this array ?
public static void main(String [] args){
String [] files = args1 ;
// or will it be String [] files = args1[];
}

View Replies View Related

Passing A Method And Searching Array

Apr 22, 2014

How to pass the methods listed below.

public ArrayList<Person> findPerson(String searchFor)

^ this method is suppose to search an array and find whatever you search (numerical or alphabetical)

I have this

public ArrayList<Person> findPerson(String searchFor) {
Main.handleSearchPerson(keyboard, searchFor);
ArrayList<Person> matches = new ArrayList<>();
for (Person p : personList) {
boolean isAMatch = false;

[Code] .....

I am not sure if how i am searching the method is correct or how to pass that to another class to put it inside of a switch statement.

View Replies View Related

Passing A Method And Searching Array

Apr 22, 2014

How to pass the methods listed below.

public ArrayList<Person> findPerson(String searchFor)

^ this method is suppose to search an array and find whatever you search (numerical or alphabetical)

i have this

public ArrayList<Person> findPerson(String searchFor) {
Main.handleSearchPerson(keyboard, searchFor);
ArrayList<Person> matches = new ArrayList<>();
for (Person p : personList) {
boolean isAMatch = false;
if (p.getFirstName().equalsIgnoreCase(searchFor)) {
isAMatch = true;

[Code] ....

I am not sure if how i am searching the method is correct or how to pass that to another class to put it inside of a switch statement.

View Replies View Related

Create A Recursion Method That Takes ONLY ARRAY As A Parameter

Mar 9, 2015

so i have this question where it wants me to create a recursion method that takes ONLY THE ARRAY as a parameter, and without using loops or static variables inside the method, and then the method returns the smallest value in that array. However, i tried making the simple if statements where i compare the first element of the array with the second element using the length of the array and decreasing it to get the next elements and compare it again by calling the recursion method, but the problem is when i call the method again, the length does not decrease, even if i store it in a variable, the variable will initialize itself again, and the length wont change.

View Replies View Related

Calculating Values And Passing From Two-dimensional Array

Jan 29, 2014

Long story short: The program takes user values (temperature) and converts them to the opposite (C >> F / F >> C)

I originally started this program with three separate arrays but then decided that it would be a good opportunity to use a two-dimensional array and one other.

The two-dimensional array has 2 rows, 10 columns. The second is a normal String array ...

Java Code:

String[][] myTemperatures = new String[2][9];
String inputAssembly[] = new String[9]; mh_sh_highlight_all('java');

I prompt the user for to enter temperature values, using a GUI and jbutton to distinguish F/C. Each time the user clicks 'continue', the values are stored into the two-dimensional array. One row holds the temperature, the other holds the C or F designation.

Java Code:

// CONTINUE BUTTON CLICK ACTIONS
class ContinueButtonListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
input = view.getTempValue();

[Code] ....

This is where I am experiencing the trouble and I cannot seem to get the Debug to work properly here. When the two-dimensional array is full OR the user clicks 'calculate' instead of 'continue', the Calculate event is performed via an ActionListener.

Java Code:

// CALCULATE BUTTON CLICK ACTIONS
class CalculateButtonListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
String hold;
Double temp;

And I get a ton of errrors ...

Java Code:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "[Ljava.lang.String;@7441b1fd"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)

[Code] ....

I imagine the issue lies within how I am handling the two-dimensional array in the CALCULATE event and/or converting the String[][] to String then parsing to an Integer.

Would this be better done is separate arrays (not using one two-dimensional, but storing 34C, 45F ... in one. I think this would be difficult for me to parse for conversions).

View Replies View Related

How To Create A New Array For Each Numbers That Are Passing Through Condition

May 26, 2014

how to translate it into Java language due to lack of experience (2 weeks). My solution I've formed in my head is: create a new array for the numbers that are in improvement and then declare a "max" variable. Check which array's length is higher and print that length. What I don't know to do is: I don't know how to create a new array for each numbers that are passing through the condition.

Note: I couldn't find anything on internet about my problem so that's why I'm here.

My code is this one:

class MyClass {
static int progresie=0;
public static void longest_improvement(Integer[] grades) {
for(int i=0;i<grades.length-1;i++){
if(grades[i]<=grades[i+1]){
progresie ++;
}
}
System.out.println(progresie);
}
}

View Replies View Related

Write A Method Called AddToOverThirty Which Takes Array Nums3 As A Parameter

Apr 22, 2014

i have to "Write a method called addToOverThirty which takes the array nums3 as a parameter. It adds 1 to all numbers that have a value greater than 30 in the array.

Add a call to the addToOverThirty method, then display a message telling what the output is followed by the results For example:The nums3 array after adding 1 to all numbers greater than 30 is10 6 15 and so on (check with the values you assigned to nums3)"its pointless because we were told not to make the array have a number over 30.

import java.lang.*;
import java.util.*;
public class LastProject
public static void main(String[] args) {
int nums1[] = new int[15];
int nums2[] = new int[15];
int nums3[] = {5,2,15,8,26,22,1,29,4,23,30,11,19,6,24};

[code]....

View Replies View Related

Creating WordCounter Class With A Constructor That Takes File Name As Parameter

Mar 4, 2014

Instructions

Create a WordCounter class with a constructor that takes a file name as a parameter

The class should have two fields: one for the file name and one for a HashMap to store word count information

The constructor should call a private method, countWords, that reads in the file and counts the word frequencies

The class should contain a get method for each field, as well as a print method that prints out the map in the following format:word:frequency

When printing, the map should be sorted by either the word order or frequency (Hint: see Collections.sort)

You should include the sample text file on Blackboard. This is what i got so far

Java Code:

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
public class WordCounter

[Code] ....

View Replies View Related

Passing File Path To Servlet Using Drag And Drop Method In Java Web

Jun 18, 2014

currently I am doing my java web application project ,and it has following steps 1) Upload the txt files 2) java servlet gets the txt file's url , read the data and do the calculation 3) pass the results

I almost finished the second step , and working on the first step .Since there are so many input files at a given time , i have to use drag and drop method to get the file's location.how to pass file's path to servlet.( servlet code can read the data from the given txt file path )software used - tomcat and netbeans 8.0

View Replies View Related

Passing Parameter From Object Of Class B To Object Of Class C By Use Of Class A?

Dec 13, 2014

Assuming that we have two classes B and C which inherit from class A. What is the best way to pass a parameter from an object of class B to an object of class C by the use of class A without using static variable and without defining a get function in B?

View Replies View Related

Converting Hex To ASCII

May 16, 2014

I try to use below codes to convert Hex String "1111737999630745" to ASCII.

When I read the result in Notepad++ with HEX-Editor plugin, I find attached image which is different from above String, there is one additional c2 and I am quite confused.

Java Code:

public static void main(String[] args) throws IOException {
Test strToHex = new Test();
File file = new File("D:/filename");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();

[Code] .....

View Replies View Related

Bin To Hex And Hex To ASCII Program

Apr 19, 2015

I need to write a program that combines everything I learned in my Java course from chapter 1-6 and 8 by Tony Gaddis at least with all the other chapters being bonus points, so I decided to write a program that tells you the binary to hex conversion or hex to ascii conversion. However I keep getting the following errors in my class, enums, and main program that I'm not sure about why. Please do not point out that the numbers in the case select are not what the hex values translate to because I know that, but I was trying to use more meaningful place holders temporarily:

These are the errors for main:

----jGRASP exec: javac BinToHex.java
 BinToHex.java:9: error: cannot find symbol
Scanner keyboard = new Scanner(System.in);
^
symbol: class Scanner
location: class BinToHex

[Code] .....

3 errors
 
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

Because of the error in the picture attached I am unable to show the remaining errors for the class and enumsjGrasp Save error for Ascii character import enum datatype.jpg

Here is the code for main:

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.*;
 /**
This program shows that you can binary to hex and hex to ascii.
*/
 public class BinToHexToAscii

[Code] .....

/**
Hex value output enumerated data type
*/
 
enum BintoHexfinalDatatype { "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F",
"10","11","12","13","14","15","16","17","18","19","1A","1B","1C","1D","1E","1F",
"20","21","22","23","24","25","26","27","28","29","2A","2B","2C","2D","2E","2F",
"30","31","32","33","34","35","36","37","38","39","3A","3B","3C","3D","3E","3F",
"40","41","42","43","44","45","46","47","48","49","4A","4B","4C","4D","4E","4F",
"50","51","52","53","54","55","56","57","58","59",&quo

View Replies View Related

ASCII Star Shape

Feb 2, 2014

I am having an awful time submitting the right program for this star pattern. 2.4: Star Pattern Write a program that displays the following pattern:

*
***
*****
*******
*****

I input the following:

// Program Challenge 2.4
2
3 public class PC24
4 {
5 public static void main(String[ ] args)
6
7 /**
Newline Advances the cursor to the next line for subsequent printing p.42*/
8
9 {
10
11 System.out.println(" *
"+ " ***
"+" *****
"+"*******
"+ " *****
");
12
13
14 }
15 }

View Replies View Related

Reading ASCII Data Correctly

Jan 21, 2015

I have two programs that talk to each other over a TCP connection. When I write the data "STX+1234" where STX is the Ascii character STX or Ctrl B and I expect the written String length to be 6 which it is. On the other side of the socket I create the ServerSocket and use the client socket's InputStream to create a BufferedReader. When I receive the string it now has 12 characters where each original character has been replaced by NUL and the character.  How do I read the string as it is originally specified without the conversion? And is the problem on the reader side or the writer side?

View Replies View Related







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