Green Bottles Activity - Printing Lyrics Of Song
Feb 23, 2014
I need to write up a code that will print the lyrics of the Green Bottles song. So it will ask the user to input a number and it will use that number to print the lyrics and then count down from that number. For example, user enters the number 5, the program will run and display:
"5 green bottles, hanging on the wall
5 green bottles hanging on the wall
and if one green bottles should fall
there will be 4 green bottles hanging on the wall
4 green bottles, hanging on the wall...." and so on.
So far I have managed to write a code that will display the number that is entered but I cant figure out how to subtract the number by 1 to continue it. My code so far:
import java.util.Scanner;
public class SomeJavaCode
{
public static void main(String[] args)
{
System.out.println("How many bottles to start with?");
[Code] ....
How to code it so that it substracts the number and repeats the rhyme till 0.
View Replies
ADVERTISEMENT
Feb 16, 2014
I'm making a simple game where there's a 10x10 grid and you can move around a selection box and you can move around. I've been trying to make the green selection box to move around but it won't move! I only have right movement in the code but it won't work so far. Here are the classes that have to do greatly with each other.
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.image.BufferStrategy;
import java.util.Random;
public class Game extends Canvas implements Runnable{
private static final long serialVersionUID = 1L;
[Code] ....
I also tried an approach where you click with the move and it snaps to a tile grid but that didn't work either.
View Replies
View Related
Jan 6, 2015
I have two classes LightController & Circle. I need to use the LightController class to do the following:
Creates an instance of Circle with a diameter of 50 and a colour of OUColour.GREEN and assigns this new circle to the instance variable light.
Sets the xPos of light to 122.
Sets the yPos of light to 162.
I am struggling to write the correct line of code to set the colour to green and set diameter to 50.
Code for the two classes below.
import ou.*;
import java.util.*;
/**
* Class LightController
* This class uses the Circle class, and the Shapes window to simulate a disco light, that grows and shrinks and changes colour.
*/
public class LightController
{
/* instance variables */
private Circle light; // simulates a circular disco light in the Shapes window
private Random randomNumberGenerator;
[Code] ....
View Replies
View Related
Feb 8, 2015
I didn't see anything specific to Android. I am a very basic beginner when it comes to JAVA and Android programming.
The app is a very simple comic strip viewer that views 3 panels of a comic strip one at a time. My problem is going from a second activity to another. I can go from the main activity to the second fine but when I press the next button to go from the second activity to the third nothing happens. I have tried a few different things but end up with either nothing happening or the app crashes.
Here is my MainActivity Code:
package net.androidbootcamp.comicapp;
import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
[Code]...
Here is the code for the second panel:
package net.androidbootcamp.comicapp;
import android.app.Activity;
import android.os.Bundle;
public class Panel2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Code]...
Here is the code for Panel 3:
package net.androidbootcamp.comicapp;
import android.app.Activity;
import android.os.Bundle;
public class Panel3 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Code]...
And here is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[URL].."
package="net.androidbootcamp.comicapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
[Code]...
I am sure it is something very simple but I am not sure what it could be.
View Replies
View Related
Dec 5, 2014
I'm working on my Android project where I created Expandablelistview with men's and women's sports. Now I have to populate each sport with my text data which contains events. I'm stack at this point, already tried few thing but that did not work. Here is my data how it looks like:
this Main (id=831962574768)
groupedFeeds ArrayList (id=831963150464)
array Object[12] (id=831963153088)
[0] GroupedFeed (id=831963152968)
category "Women's Golf" (id=831962986192)
feeds ArrayList (id=831963152992)
[1] GroupedFeed (id=831963153592)
[Code]...
I have here my Main method where I have to pass data to each of my sports(activities). I tried to create a for loop and then pass result to my sport(activity) but I'm doing something wrong and can not get that work. Here is my code:
GroupedFeed findFeed(String locateSport){ //here I tried to create a loop which gonna search for certain sport in array list
//and then pass it to gfResult. }
public boolean onChildClick(ExpandableListView parent,
android.view.View v, int groupPosition, int childPosition,
long id) {
switch (groupPosition)
[Code]...
View Replies
View Related
Jun 1, 2014
I am trying to develop an application which will be showing a TimeSeries graph(related library JFreeChart) displaying network activity related to a particular network interface embedded in a JFrame.I have created a JPopUpMenu which is having containing a list of JMenuItems showing network interfaces as their String values.Menu is popping up correctly
Further I am selecting a JMenuItem related to a particular network interface to show network activity in TimeSeries graph.On selecting a JMenuItem I can see that graph is moving on constantly but not able to see any network activity.
Pasted the code below :
package com.ankit.analyser;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Window;
import javax.swing.JFrame;
[Code] .....
Further I can see that packetArrived method of PacketListener is not being overridden by class PacketHandler as I am not able to see data packets on console and static list in main class is also empty.
View Replies
View Related
Mar 8, 2014
I'm doing a project with very defined requirements. Input and output will be done to and from a file. Both the input and output files should have the same format. Each file will consist of a series of lines formatted as follows:
Year Rank Artist Title
That is, each line of the file will consist of the year, rank, artist, and title of a single song, with each of the fields separated by tabs ( ). Output files must maintain this format—you should be able to use the output file of one run of the program as the input to another run.
The first part of my project is to make a Song class, with 6 methods:
public static Song parse(String s) { //Parse a string of the form “Year Rank Artist Title” and create a Song object with the given values.
}
public int getYear() { //returns the year of the song
}
public int getRank() { //returns the rank of the song
[Code] .....
So far, I have worked out my Song class like this:
Java Code:
import java.util.Scanner;
public class Song {
private int year;
private int rank;
private String artist;
private String title;
[Code] ....
I know there's definitely a problem with my parsing, as I am getting the
Exception in thread "main" java.util.NoSuchElementException
when I attempt to input a test String at my variables.
Should I try using StringTokenizer and Integer.parseInt()? I think that perhaps the reason why an error is occuring is because the String is being parsed into Strings and there are no int values to be inputted into the year and rank variables.
Or is there a way to do this with Scanner?
View Replies
View Related
Jul 22, 2014
In my card game applet I have to play some music and the user must have the ability to play, stop and pause the song using buttons. I got the play and stop to work easy but I'm unable to add the pause option/method.
View Replies
View Related
Feb 24, 2014
i want to design a media player but my program can't play any song it is showing me error "Uncompilable source code - cannot find symbol
symbol: class MediaPanel
location: class media.Media
at media.Media.main(Media.java:28)"
This is my code.
package media;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFileChooser;
[Code] .....
I got the code from [URL] .....
View Replies
View Related
Aug 16, 2014
I have created a playlist class that ask the user to enter a song name and etc. What I want to do is have the mp3 class plays the song that the user has entered, but I don't know how.
Here are my codes:
import java.util.Scanner;
public class PlaylistDriver
{//Start of class
public static Playlist list;
public static void main(String[] args)
{//Start of main
list = new Playlist();
[code]....
View Replies
View Related
Nov 6, 2014
I'm making a program where the user enters an ID number and can submit the amount of sales that person made for a specific product and write to a file. One of the things I have to do is making a running sum of the sales for each product for all people combined as well as an accumulation of the a persons sales every time he enters data. Everything seems to be working execpt my values like person1Total, person2Total...etx and product2Total.
When I try to write them to the file, they always come out at 0.0 even though they should be the sum of the indexes of the array sales.
import java.io.*;
import java.util.Scanner;
public class SalesReport {
// private static double p1Total, p2Total, p3Total, p4Total;
private static double product1Total, product2Total, product3Total, product4Total, product5Total;
private static double person1Total, person2Total, person3Total, person4Total;
public static void main(String[] args) throws IOException
[code]....
View Replies
View Related
Mar 11, 2014
I am trying to print out a list of usernames for my chat program. It currently works except for the username portion. The Server sends a specific line that tells the client to print it as a username. That line is name//name. For example, if the name of the client was Eric, then the server would send Eric//Eric to the client. The client will then receive the line through a buffered reader. However, my current code keeps getting an error at the i=input.substring... line. Its an IndexOutOfBoundsException: String index out of range: -1.
class ChatThread extends Thread {
ChatServer cServer;
String[] sentence;
int i;
public void run() {
String input = "Eric";
try {
[code]....
View Replies
View Related
Apr 15, 2014
So for fun I've decided to write a program that can keep track of a simple card game my friends and I designed. I've built a class for an array, that stores the basic stats of each card. I need to be able to access this array from another class, that will print the array information to a file, so we can easily keep track of who's cards have leveled up and their stats. The main class will also be using a random number generator to determine how much damage the attacker/defender deals and takes respectively. So far I have the random number generator built as well. I'm just having issues creating a print to file class and what I need to change in my array class to make it accessible by the other class that prints it to a file.
public class StartingStats {
public static void main(String[] args)
{
//Variable to use for how many spots in a stat array there are
final int statArray = 2;
[code]...
what I need to change so that a print to file class can access EACH array in this array folder. Also if any cookie cutter printToFile class I could use/borrow/change that'd be really useful, as I've never done any printing to file before. Also, the levels of each stat and exp will be changing so that's why I need a separate class to print so that I can call it when it's been updated so we always have the most up to date stats saved.
View Replies
View Related
Nov 17, 2014
My array isn't printing. I have tried everything. I have tried putting a nested for loop in different methods but still no luck. I have also tried System.out.print but that prints random characters/numbers.
import java.util.Scanner;
public class Square
{
public static void main(String[] args)
[Code].....
^For some reason the site doesn't show the spaces between the *. It's supposed to be a 5x5 square.
View Replies
View Related
Mar 28, 2014
I have a hashmap of the form HashMap <String, Set<String>>I am trying to create a method with one argument. The argument is a key for the hashmap, if it exists it should print out the key and the associated values. I'm falling over at even getting it to print the key, it keeps printing all the keys from within the hashmap as I don't know how to load the argument into it. I have this so far
Java Code:
public void printValue(String club)
{
boolean result = clubMap.containsKey(club);
if (result)
{
String key = clubMap.keySet(club).toString();
System.out.println(key );
[code]....
View Replies
View Related
Sep 24, 2014
I've been working on the below code for a couple days in my spare time. Just a simple little text-based RPG. I'm brand new at programming and Java, so excuse the bad syntax. There's probably easier ways to go about what I'm trying to accomplish, but all we've learned so far in class is while loops and if statements. Anyways, the problem is that the statement "Really? Ten health points[...]yes or no?" in my code is printing twice.
int health = 0;
boolean enterHealth = false;
String verifyHealth = "";
boolean test6 = false;
boolean test7 = false;
boolean test8 = false;
[code]....
View Replies
View Related
May 3, 2015
Lets say in method 1 I want to print the numbers 1 - 10. Easy stuff. I then print that to the
PrintStream outFile = new PrintStream(new File ("output5_01")); I declared.
Now I'm in another methods, How do I print lets say 11- 20 without erasing the first methods printed results?
so my desired results would be
outFile
-------------------------------
(From 1st method) 1- 10
(From 2nd method) 11-20
As of now the second method always over writes the first. None of my books cover this and its very frustrating when the entire code is done but this won't let me write to the file
View Replies
View Related
Jun 12, 2014
Im trying to make a question game, much like a spin off from Trivial Pursuit. In this code, I call classes to get a random number. This number determines what category the question will be from. Coinciding with this number, the "if" statements go and pull the questions and answers from an alternate class. My problem is that when I try and output what should be the question and the 3 answers, its outputs "null" for each String?
This is my first class, which is just the class for the player.
Java Code: /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
[Code].....
View Replies
View Related
Jan 10, 2015
I finally got this to work but only by printing out the value of each number to debug as such, was there an easier way to do it that I missed?
public class Statistics {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// variables used
double num1;
double num2;
double num3;
double num4;
double num5;
double num6;
Scanner input = new Scanner(System.in);
//receive number and add it separately
[Code] ....
View Replies
View Related
Mar 10, 2014
I want to know how to print this type of pattern when a name is given ???
Example:
name given TEJA
Capture.PNG
View Replies
View Related
Mar 2, 2015
How do you replace negative zero value with a zero value when Printing results:
I want to remove the minus sign in -0.0000 and instead have 0.0000.
I am Printing coordinates and I do not want to have negative zero.
the coordinates are defined as double.
System.out.format(java.util.Locale.US," %.4f %.4f %.4f %.4f%n"xCur ,yCur,xNext,yNext);
0.0000 1.0000 -0.0000 0.0000
View Replies
View Related
Jan 24, 2014
I am writing a Java permutation program, it takes in N and k and gives k amount of combinations based on N length.
That portion works, but the portion I have that does not work is when k is greater then 1, the array is then then printing strings out of index.
The perm algorithm ends on index - 1 for moving characters but then I push all those characters into an Array List, I would think I could print them off however I want from there but that is not the case. I'll include the minimum amount of code possible.
//permString = 1234 or something, it doesn't matter
//Use Case N = 4 k = 3, prints out 123,124,132,134 ect
//Use Case N = 4 k = 2, error index out of range but only on the printing function; the perm function doesn't take k and
//is based on length
//the "" is just an empty string
permNow("", permString);
}
[code].....
View Replies
View Related
Apr 27, 2014
I have a project to create an application where you can print all the detail to be written on a receipt (no more manual writing). I already have blank receipts. All I want to know is how to do that printing the details at exact position in my blank receipt. I'm starting to read about Jasper Reports but I don't know how it will work since most of its example are creating template.
View Replies
View Related
Feb 28, 2014
why my code is not printing the matrix and sum?
The Java-program Matrix below first asks the user for the number of rows and columns in a matrix. After this the program asks for the values of the elements. Finally, program prints the elements of the matrix and their sum on screen. Your task is to create the missing methods. Check the example print to see how to modify the print. When printing the matrix, values on the same row are separated using tabulator.
Program to complete:
import java.util.Scanner;
public class Matrix {
public static void main(String[] args) {
int rows, columns;
Scanner reader = new Scanner(System.in);
System.out.print("Type in the number of rows: ");
[code]...
Write the missing methods here / Methods are written in the text box below.
Example output
Type in the number of rows: 3
Type in the number of columns: 4
Type in the element 1 of the row 1: 1
Type in the element 2 of the row 1: 2
Type in the element 3 of the row 1: 3
Type in the element 4 of the row 1: 4
Type in the element 1 of the row 2: 5
[code]...
Matrix:
1 2 3 4
5 6 7 8
9 10 11 12
Sum of the elements of the matrix: 78
my code
import java.util.Scanner;
public class apples {
public static void main(String[] args) {
int rows, columns;
Scanner reader = new Scanner(System.in);
System.out.print("Type in the number of rows: ");
[code]...
View Replies
View Related
May 17, 2015
I am learning while loops but the output I am getting is not what I want? My class:
public class BottlesOnWall {
public static void main (String[] args) {
int x = 99;
while (x > 1) {
System.out.println(x + " bottles on the wall!");
[Code] .....
The output I am getting is this:
99 bottles on the wall!
98 bottles on the wall!
97 bottles on the wall!
96 bottles on the wall!
95 bottles on the wall!
[Code] ....
I want it to stop on "2 bottles on the wall!" and then print "Only 1 bottle left on the wall!". How do I go about doing that? I have tried different variations of the condition (x>1), I have tried (x>5) but it still goes down to 1 bottle?
View Replies
View Related
Dec 1, 2014
The code below gives me an alphabet and the numbers 0-9 printed out in column, the job is to print it in line (in a row).
/**
* Alphabet and numbers
*/
public class Alphabet {
public static void main() {
char letter;
char number;
[Code] ....
View Replies
View Related