I've been given an assignment for my Programming Fundamentals class that requires the user to enter a word/sentence to encrypt or decipher, as well as requiring the user to enter a key in which to encrpyt/decrypt the input by.
So a = no shift, b = a shift by 1 and so on.
But I'm completely lost as to what to do, and after searching for Vigenere Cipher topics, they look completely different to mine and (hardly) include prompts?This is my code:
/** * @(#)VigenereCipher.java */ import java.util.Scanner; public class VigenereCipher { public VigenereCipher()
Im running into some problems with the Java compiler. This is my code:
public class DoublyLinkedList<T> implements SimpleList<T> { protected Node dummy; protected int n; public DoublyLinkedList(){
dummy = new Node(); dummy.next = dummy; dummy.pre = dummy;
n = 0;
[Code] ....
I want to use a dummy node in my implementation of the Doubly Linked List, so it will be easier to code all the methods I need to write. I keep on getting a problem with line 14 and 15:
dummy.next = dummy;
dummy.pre = dummy;
// cannot find symbol variable next (compiler error)
I am trying to find the GCD, add, and remove the biggest and smallest fraction, however I am having trouble getting user input into the array and getting the information out of it (Variable f).
Scanner keyb = new Scanner(System.in); Fraction[] frak = new Fraction[7];
Main_Class try { for (Fraction f : frak){ // for each array in frak print f; System.out.println("Enter Numerator"); int num = keyb.nextInt(); System.out.println("Enter Denominator"); int den = keyb.nextInt(); f = new Fraction(num, den);
I am writing a program to store books (Book class) in volumes (Volume class). Within the main class (DemoVolume) I am doing a couple different things. I want to ask the user if they are creating a new array, if yes, I was to create a new array with a variable names assigned by the user. Is this possible? The reason is I want to allow the user to be able to search their library of volumes. If no, then the user will enter the book information and I will assign it to an array unassignedVolume that will contain individual books. I would also like to create book objects that are defined with the book name, if this is possible. I'm just messing around and trying to deepen my understanding of JAVA. My main issue is how to allow the user to title the volume (array variable).
import java.util.Scanner; public class DemoVolume { public static void main(String[] args) { Scanner input = new Scanner(System.in); String [] volume, unassignedVolume; Volume volumeOne = new Volume("JAVA", 3, volume);
I'm studying about arrays and I have some questions:
First, is there any difference between these two?
Java Code:
int x[] = new int[3]; int[] x = new int[3]; mh_sh_highlight_all('java');
It seems to me when I try them they do exactly the same, is that correct?
Second, more important question. If I want to make an int variable that refers to the index number of an array, how do I write? For example if we have
Java Code: String[] string = new String[10]; mh_sh_highlight_all('java');
And I want to have a variable "int n" that refers to an index number, so that if I set n = 5 then string[5] is selected. Note that the int n is NOT an array, but just a regular integer variable. How can I do that?
I'm trying to set a variable to point to the last full cell of an array and then create a new larger array and then have the variable be updated to point to the new array's last full cell index value.
a) Should the variable be declared static? b) What would be the best initial value to set this variable to? Shouldn't it correspond to a <for> loop index rather than a solid integer?
private lastfullcell = a[i]; private int [] a;
c) How would you update <lastfullcell> because if you passed the index through a method's loop index isn't the array index value garbage collected after the method completes?
I am creating a hangman game and I want to read in a list of words from a text file, but after the user inputs the name of the text file. I get 'Exception in thread "main" java.lang.NullPointerException'.
Here is the code, where I think the problems lie.
public void runModel(){ ArrayList<String> pirateWordsList = new ArrayList<String>(); System.out.println("What is the name of the file you would like to load? (The file included is called piratewords.txt'"); Scanner in=new Scanner(System.in); String file=in.next(); load(file);
[Code] ....
The full error message is this:
Exception in thread "main" java.lang.NullPointerException at uk.ac.aber.dcs.pirate_hangman.Model.load(Model.jav a:108) at uk.ac.aber.dcs.pirate_hangman.Model.runModel(Model .java:45) at uk.ac.aber.dcs.pirate_hangman.Main.main(Main.java: 6)
Im trying to create a program in which I read line by line the contents of a text file, and then report each letter along with its frequency. I was wondering how to read through the lines and process it so that my program knows to increase by a number each time a letter appears in my text file. For example, if A appears in my file 5 times, B 3 times, and C 0 times I want to eventually print out
A -- 5 B-- 3 C-- 0
My first thought was to do this using array lists but is there any way I could do this without using one?
method called []getLetterGrades but the only hint My professor told me was that I needed to declare another array list for this method and he wouldnt tell me anything else so bummer. But I don't understand why if what we are returning is a char. It would make sense to return an array list of char to get letter grade. Which is what i did but since the function is a char, the array list character wont work as a return.Primarily i would like to know the type that is needed. I just want an explanation for an array list in this method and how it would serve in this method.
Directions: public static void initialize(ArrayList names, ArrayList sores)
You should write a function that sorts both array lists, based on the values in the scores array list. This is one of the more conceptually challenging parts of the assignment. You want to sort the scores array list, and simultaneously alter the names array list so that the names continue to line up with their respective scores by index. In the example data above, when the score 9900 moves to the first element of the scores array list, the name "Kim" should also be moved to the top of the names array list. The function should have the following signature:
I'm having trouble figuring out how to sort the lists.
import java.util.ArrayList; import java.util.Scanner; public class Assignment5 { /** */ public static void main(String[]args) { intializeArrays();
I had to write a program that prompts the cashier to enter all prices and names, adds them to two arrays lists, calls the method that I implemented, and displays the result and use 0 as the sentinel value. I am having difficulty coming up with a for loop in the method, I believe I have the condition right but I am having trouble with the statements. I now know that String does not have the get property, but I have only done examples with integers and I am not very good with for loops and wouldn't know how to fix it.
public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Double> sales = new ArrayList<Double>(); ArrayList<String> names = new ArrayList<String>(); System.out.print("Enter Number of Customers"); double salesAmount; System.out.print("Enter Sales for First Customers"); salesAmount = in.nextDouble(); while(salesAmount != 0)
I am stuck on this exercise and I don't know what exactly is wrong. I think it's something with the .remove and the for each loop, but I am not sure.
public class seven { public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("aaa"); list.add("brr"); list.add("unni");
[Code] ....
This is what i get
Exception in thread "main" java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(Unknown Source) at java.util.ArrayList$Itr.next(Unknown Source) at seven.removeDuplicates(seven.java:24) at seven.main(seven.java:18)
private int coin; Money(int c) { coin = c; } int showCoin() { return coin; }
and for a test class, I need an array list with a couple of coins in it (i.e. ONE_POUND, TWO_POUNDS) and a loop that adds together the values of the coins in the list and prints the result. How can I do this?
I have this very simple application just to test console input:
import java.util.ArrayList; import java.util.Scanner; public class WriteTester {
[Code]....
When I let it run, only every third entry is put into the array list and I have to hit "enter" three times for the "break" in line 21 to trigger. I cannot find out why.
Im making a simple code to add an array to a List (the code im referring to is <String> )
import java.util.*; public class L5_ArrayListProgram { public static void main(String[] args){ String[] things = {"lasers","ghouls", "food", "dark"}; List<String>list1 = new ArrayList<String>(); for(String x: things) list1.add(x);
My simple question is - what are the <String> ...<String> for? I understand it makes the list1 variable a string, but why is it made like this? do we usualy use <String> when we need to make a variable a String?
My assignment is to create an array list and compare the total salary of two salespeople. I'm wondering if I can use JOptionPane to select an existing sales person from the list and print their information.
I am not having any trouble with the calculations and comparisons, but I am finding limited resources on "searching" for a specific person with JOptionPane.
Here's what I have so far.
public class SalesPeople { String personName; double annualSalary; double salesAmount; double percentComission; public SalesPeople(String xPersonName, double xAnnualSalary, double xSalesAmount, double xPercentComission) {
I have to make an applet that uses an array to list 5 songs and the applet has to scroll the list of song titles, one at a time, each song title should start at the top of the applet and scroll to the middle then, scroll off the right hand side, each new song title should scroll in a different color, the applet should loop, when it gets to the end of the list, start over again at the beginning of the list. the code compiles fine put when I go to run the applet nothing shows up in it and a wall of text appears in the command prompt.