Program Does Not Print The List?
Aug 22, 2014
the program does not print the list when i select choice 3 it only prints the original 2 elements, same happens if i use if else statements instead of switch statement. Quote public class linklistdemo{
public static void main(String args[]){
while(true) {
System.out.println("press one enter element");
[Code]....
View Replies
ADVERTISEMENT
Apr 11, 2014
I have been working on this Java Gui program and i cant get it to print to the textbox correctly.i originally had it displayed in a dialog window but it would print one integer a time in a seperate window.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;
import java.io.*;
[code]....
View Replies
View Related
Nov 23, 2014
I am having an issue trying to print different types of arrays using one method. Eclipse tells me to convert my print method for each array type:
change method 'printList <e>' to 'printList(ArrayList<integer>)'
change method 'printList <e>' to 'printList(ArrayList<Double>)'
change method 'printList <e>' to 'printList(ArrayList<Character>)'
change method 'printList <e>' to 'printList(ArrayList<String>)'
I would like to accomplish printing all four different arrays using one print method. How to accomplish it or provide examples or links to examples?
import java.util.ArrayList;
public class SortArrayList {
public static class Sort {
[Code].....
View Replies
View Related
Oct 21, 2014
I'm having some trouble with my project. I have filled the getters using an array and what I now need to do is get the user to type in a day and print the corresponding getters to the lines the day is on in my text file.
{
File file = new File("DailyJobs.txt");
Job newJob = new Job();
try (Scanner scanner = new Scanner(file);)/>
{
while(scanner.hasNextLine()) {
String line = scanner.nextLine();
[Code] ....
This is what I've attempted in terms of entering the day. It recognises the number of lines that has the inputted day but prints out only the very last job ID in the text file.
90301,14304,ITGURU,11/11/2014,Tuesday,735.75,1204,1205
90302,14314,ROK5TR,12/11/2014,Wednesday,335.75,1205
90303,14318,HRTBRK,13/11/2014,Thursday,125.5,1200
90304,14310,EVOH8R,14/11/2014,Friday,1207.95,1211
90305,14300,G4MER,11/11/2014,Tuesday,500,1204,1202
[Code] ....
This is the text file, the first number on each line is the Job ID and always prints the last line regardless of the day I enter.
View Replies
View Related
Jan 1, 2015
AddItemToFront(Item p) : This method will create a new Node with the Item object as its data value and then add the newly created node to the front of the linked list.
DisplayItems(): This method will traverse the linked list from first node to last node and print data value ( i.e., id, name, type and price of the Item object) of each node.
RemoveItemAtPosition(int n): This method will remove the node at position n in the linked list. Assume that the first node of the linked list has a position number of 1 and the second node has a position number of 2 and so on.
This is my Code
AddItemToFront
public void AddItemtoFront(Item p)
{
Node newNode = new Node(p);
newNode.setLink(head);
head = newNode;
[Code] ....
I don't know what am I suppose to do inside the remove method
View Replies
View Related
Mar 9, 2015
How can i convert this linked list code to a read from input.txt
The first line in the input file will give the elements to initialize the linked list with. Consecutive lines will provide operation instructions.
Your code should read one line at a time. After reading each line, it should perform the corresponding operation and print the linked-list on the console.
If an operation is not possible, it should print "N/A".
Sample input file. Please note, the comments (// ...) are given for explanation, the input file will not have them:
4, 5, 6, 3// First line. This will provide the initial values for the linked list : 4->5->6->3
1, 9// Add a 9 at the front of the linked-list. After this operation the linked-list should be: 9->4->5->6->3
2, 1// Add a 1 at the end of the linked-list. After this operation the linked-list should be: 9->4->5->6->3->1
3, // Delete the first node in the linked-list. After this operation the linked-list should be: 4->5->6->3->1
4, // Delete the last node in the linked-list. After this operation the linked-list should be: 4->5->6->3
5, 11// Delete the node with the value 11 in it. Since this is not possible, it should print "N/A"
5, 6// Delete the node with the value 6 in it. After this operation the linked-list should be: 4->5->3
Sample output to the console:
4->5->6->3
9->4->5->6->3
9->4->5->6->3->1
4->5->6->3->1
4->5->6->3
N/A
4->5->3
My Code:
LinkedList.Java
class linkedList
{
protected Node start;
protected Node end ;
public int size ;
[Code] .....
View Replies
View Related
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
Oct 6, 2014
I have an Array of objects that contains strings. I am new to Java and have read books, the Java docs, and searched the Internet for my problem to no avail. How can I get my strings to print in a list so that the user can select an object to manipulate its attributes? I have a class called Instruments and created 10 guitar objects. Here is the code:
Instrument [] guitar = new Instrument[10];
for (int i = 0; i < 10; i++) {
guitar[0] = new Instrument("Guitar 1");
guitar[1] = new Instrument("Guitar 2");
guitar[2] = new Instrument("Guitar 3");
guitar[3] = new Instrument("Guitar 4");
[Code] ....
View Replies
View Related
Apr 28, 2014
I am trying to invoke some methods in a for loop in order to print some info stored in a List. But for some reason, compiler pops a message saying "cannot find symbol - method getEmpID(). You are using a symbol here (a name for a variable, method or class) that has not been declared in any visible scope." But I am pretty sure that method getEmpID (as also getName(), getAfm(), and payment() ) have been declared as public.
Note: My List contains objects of different type (SalariedEmployee, HourlyEmployee). I hope this is not the factor causing this problem.
Java Code:
import java.util.*;
abstract class Employee{
private String name = "";
private String afm = "";
private long EmpID;
static long count=0;
[code]....
View Replies
View Related
Oct 7, 2014
I am new to Java and have read books, the Java docs, and searched the Internet for my problem to no avail. I have an Array of objects that contains strings. How can I get the object's strings to print in a list so that the user can select that object to manipulate its attributes? For example, the user can select "Guitar 1" from a list and manipulate its attributes like tuning it, playing it, etc. I have a class called Instruments and created 10 guitar objects.Here is the code:
Instrument [] guitar = new Instrument[10];
for (int i = 0; i < 10; i++) {
guitar[0] = new Instrument("Guitar 1");
guitar[1] = new Instrument("Guitar 2");
guitar[2] = new Instrument("Guitar 3");
guitar[3] = new Instrument("Guitar 4");
guitar[4] = new Instrument("Guitar 5");
guitar[5] = new Instrument("Guitar 6");
[code]...
View Replies
View Related
Feb 1, 2015
I'm trying to make a program that generates 20 random integers between 1 and 20 and then prints the list of random numbers to the screen. After that, I want to print a different list to screen with the same numbers from the first list only skipping any number that has been already printed to the screen. So two lists are printed to the screen. The first one has 20 random numbers. The second one has those same 20 numbers but only prints the numbers in the first list that aren't duplicated. So if m
y list of 20 random integers contains three 2s and two 14s, only one 14 and one 2 is printed to the second list. Currently, my code generates 20 numbers from 1 to 20 and stores those numbers in an array but I don't know how to print solve the second part of my problem. I don't know how to print the s different list only without duplicate numbers. As a result, my output is nothing because it doesn't print any number from the first list as oppose to skipping only duplicate one.
public void randomNum(){
System.out.println("Twenty random integers: ");
int max = 20; // max value for range
int min = 1; // min value for range
Random rand = new Random();
int[] all = new int[20];
[Code] ....
View Replies
View Related
Oct 24, 2014
so I need my program to print in decimal format and I keep getting an error saying that it cant find symbol "decimalFormat". here's what I have so far.
import java.util.Scanner;
public class GPACalculator {
public static void main(String[] args) {
int creditHours = 0;
int gradePoints = 0;
[Code] .....
View Replies
View Related
Oct 19, 2014
how to print from bluej onto actual paper? how to do the formatting and configuration etc.
View Replies
View Related
Feb 4, 2015
When I run this code, it is supposed to get one value from turnTimer(); and return it, just as a test. This works when I enter a valid pit. For example. If I were to input "A" when it's player one's turn, it will return 1, like it should. However, if I were to type "H" when it's player one's turn, it returns "Not a valid pit!"(like it should) but then it also returns 12. It shouldn't know that H is 12 because it's in a separate method. I'm confused as to why it's printing both values.
import java.util.*;
public class Mancala
{
static Scanner input = new Scanner(System.in);
public static int pit;
public static void main(String[]args)
{
Mancala mancala = new Mancala();
int[] board = {0,3,3,3,3,3,3,0,3,3,3,3,3,3};
[code]....
View Replies
View Related
Jul 11, 2014
Write a program to create an integer array of size 20. Then, the program should generate and insert random integers between 1 and 5, inclusive into the array. Next, the program should print the array as output.
A tremor is defined as a point of movement to and fro. To simulate it, the program will generate a random number between 0 and 19, which represents the location in the array (i.e. index number). Then, the 3 numbers to the left and right of this location should be reset to the value 0. If there isn't 3 numbers to the left and right you may assume a lesser number depending on the boundaries of the array.
Then, the final array should be printed as output. There is no user input for this program.Your program must include, at least, the following methods:
-insertNumbers, which will take as input one integer array and store the random numbers in it.
-createTremor, which will generate the random number as the location and return it.
A sample run of the program is shown below:
Sample output #1:
Array:1 2 2 3 1 5 4 2 3 4 4 2 1 1 3 2 1 4 3 2 1
Random position: 5
Final Array:1 2 0 0 0 5 0 0 0 4 4 2 1 1 3 2 1 4 3 2 1
View Replies
View Related
Dec 31, 2014
My code:
public class Fibonacci {
/**
* @param args
*/
public static void main(String[] args) {
int f[]=new int[100];
for(int j=0; j<100;j++){
f[j]=j;
[Code] ....
How can I improve my code?
View Replies
View Related
Jan 24, 2014
write a program that would ask for the five names using loop statement and print all names .
View Replies
View Related
Mar 19, 2011
import java.io.*;
public class Netaji
{
[Code]....
View Replies
View Related
Mar 17, 2014
I have printed the result of my program into an output file.
For some reason I can't figure out how to get the file output.txt to actually print.
I've tried printing it like I would normally print a file but it's not working.
Java Code:
final PrintStream console = System.out;
File file = new File("output.txt");
PrintStream out = new PrintStream(new FileOutputStream(file));
System.setOut(out);
System.out.println(collection.toString());
System.setOut(console);
What do I do after this? mh_sh_highlight_all('java');
View Replies
View Related
Nov 19, 2014
I have to use methods and loops to code this program. Cannot use any java set or any built in java shortcuts!
import java.util.Scanner;
public class setPractice {
public static Scanner kbd;
public static final int MAXSIZE = 20;
public static void main(String[] args) {
kbd = new Scanner(System.in);
[Code] .....
This is the input I put in my code and this is the output:
How many numbers will be in the 1st set: 3
Enter list of integers for 1st set:
34
2
56
The ascending order for 1st is:
2
34
56
How many numbers will be in the 2nd set: 4
Enter list of integers for 2nd set:
56
2
33
6
The ascending order for the 2nd set is:
2
6
33
56
The intersection of the two sets is: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The difference of A-B is:
View Replies
View Related
Oct 1, 2014
Description of the program: read a sequence of positive integers from terminal. When user types
-1, the program will print out the largest number and exit.
Program mid.java
import java.util.Scanner;
public class test
{
public static int num;
public static void main (String[] args)
{
Scanner in = new Scanner(System.in);
num = in.nextInt();
int large = num;
while(num > 0);
{
if(0 > num && num > large)
large = num;
}
System.out.println("The largest number is : " + large);
}
}
View Replies
View Related
Aug 2, 2014
2.Check the Vehicle...Assume that vehicles are going through a two-way traffic intersection. There are three types of vehicles: car, motor bikes and trucks. Generate a series of 10 random integers, between 1 and 3, inclusive. The numbers represent the type of vehicle as stated below:
NumberVehicle Category
1 Car
2 Motor bikes
3 Trucks
Write a program, using a for loop, to count how many vehicles going through the traffic intersection are cars, motor bikes and trucks. Then, the program should print out the numbers for each vehicle category. There is no user input for this program.
View Replies
View Related
Nov 27, 2014
I am working on a contact list program with a GUI for a school project.I'm running into all kinds of issues when trying to update the JList in my GUI which displays the contacts.I think my issues are being caused by a lack of synchronization between the contact list that stores the data, and the contact list that is being displayed.I've tried all kinds of getters and setters, passing array indexes, passing array member objects etc.
General rundown of how I want the GUI/Code to work: When I select an object in the JLIst, the fields on the right should display that objects information.When the "Add Contact" button is created, a new blank contact should be created and added to the Contact List, and then displayed in the JList.When a field on the right side of the GUI is updated, the object in the contact list is updated simultaneously (using document listener), and therefore the JList would also be updated.
View Replies
View Related
Nov 11, 2014
I'm trying to print out the results of a program that calculates the number of seats the parties will get in an election.I have to print the partial results and the national results.
I can print te number of seats per party in each constituency, but how can i sum all seats per party in each constituency and print the national results?I'm working with vectors, which I know it might not be the best option, but everything is working, except the fact that I can't loop throuhg the vector and retrieve the total sum per party.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.Is it possible, or doIhave to create a method in Parties class to solve the problem?
This is what I have now.
for (Parties p : h.geral) {
show += String.format("Constituency - %5s - %5s - %d%n",
p.getConstituency(), p.getParty(), p.getNum_seats());
}
View Replies
View Related
Oct 14, 2014
This is my program
import java.util.Scanner;
import java.text.DecimalFormat;
public class Lab6 {
public static void main(String[] args) {
int F;
double C = 0;
[Code] ......
output
0 1 2 3 4 5 6 7 8 9
0 degree Fahrenheit equal to :-00.00 degree Celsius
1 degree Fahrenheit equal to :-00.00 degree Celsius
2 degree Fahrenheit equal to :-00.00 degree Celsius
3 degree Fahrenheit equal to :-00.00 degree Celsius
4 degree Fahrenheit equal to :-00.00 degree Celsius
5 degree Fahrenheit equal to :-00.00 degree Celsius
6 degree Fahrenheit equal to :-00.00 degree Celsius
7 degree Fahrenheit equal to :-00.00 degree Celsius
8 degree Fahrenheit equal to :-00.00 degree Celsius
9 degree Fahrenheit equal to :-00.00 degree Celsius
I don't know why the program is not calculating the C degree ?
View Replies
View Related
Apr 6, 2014
I have to make a program on J2Me which I don't have a clue, the question is :
-------------
"Initial display is a text box, with a command button "Generate". When the user enters the list type and clicks on the Generate button, the application asks count of elements and gets the elements and finally displays the list."
--------------
View Replies
View Related