Stars Program - How To Make Hourglass

Apr 30, 2015

I just recently started programming and came across the star patterns which normally I am able to do extremely quickly except with this one. I am trying to make a hourglass but I seem to only be able to make the top of it. How to do the opposite so I can finish the hourglass.

package hourglass;
class Hourglass {
public static void main (String[] arguments){
for(int j=1;j<=5;j++) {
for(int i=1;i<=j;i++)

[Code] .....

View Replies


ADVERTISEMENT

Print Upper Half Of Hourglass

Aug 26, 2014

I am only able to print upper half of the hourglass.

public static void printHourglass(int size, char symbol) {
int count = 0;
int count2 = 0;
boolean lower = false;
for(int lines = 0; lines < size; lines++)
{
//upper half

[code]....

View Replies View Related

Return Height Of Heap Of Sand In Bottom Of Hourglass

Nov 18, 2014

I am working on program and have been struggling to get around step 5 and 6 given below.

I have got on with the first couple of points. Where to begin with steps 5 and 6.

Java Code:

class Hourglass {
int height;
int bottomHalf;
public Hourglass (int h) {
height =h;
}
public Hourglass (){
height=3;
}

/*Write a method dropGrain that simulates one grain of sand falling into the bottom half of the Hourglass. If all the sand is already at the bottom before a grain is dropped, this method should cause the hourglass to be flipped, meaning that all the sand will be in the top again. Then, one grain of sand should fall. */

//Hint: this method can be quite short. All you need to do is update one attribute.

public void dropGrain(){
}

/*Write a method getHeapHeight() which returns the height of the heap of sand in the bottom of the hourglass.

Hint: a triangle of height h contains h*h grains (=1+3+5+...+h).

So determining the height when the amount of sand in the bottom half is a square (1,4,9,16,...) is easy. Think about what happens if the amount of sand is not exactly a square.*/

public int getHeapHeight() {
} mh_sh_highlight_all('java');

View Replies View Related

Create A Pattern Of Stars

Jul 2, 2014

So I'm studying for a test i have coming up on recursion so i was playing around with it. I ended up making a pattern of stars that look that such :

*
**
***

The code i had for that was

public void makePattern(int size){
if(size == 0){
System.out.println();
}
else if(size > 0){
System.out.print("*");
makePattern(size - 1);
}
}

I was wondering if i wanted to expand on this and make it do something like

*
**
***
**
*

What condition would i have to add i was struggling trying to figure it out...

View Replies View Related

Recursive Method And Printing Out Stars?

Nov 23, 2014

KtMok1t.jpg

Below is what I go so far, but how to do star C and E.

public class PrintTriangle
{
public static void printStars (int star)
{
for (int number = 0; number < star;number ++)
{
System.out.print("*");

[Code] ....

View Replies View Related

Model Galaxy - Multiple Stars With Different Masses

Mar 12, 2014

Here is a link to the program: [URL] ....

I am trying to model a galaxy so that I have multiple stars certain distances away from each other and with different masses.

The accretion and than cylinder expansion happens with just about every galaxy.

I have a few questions.

First My computer only runs this if the number of particles is in the 500s. If that's the case How can I increase the probability that I will when I get to it have a red giant?

Second how can I modify this so that I have a timescale during which white dwarfs form from some stars and you see in the single stars either no supernova or nova just degeneration or a type 2 supernova and in binaries a type 1a supernova which is like a type 2 supernova of 1 star when it is a red giant, that giant becoming a white dwarf, the other star becoming a red giant, and then the white dwarf sucking gas from the giant until it explodes and ejects its companion?

Third how can I make this compacted and taking up less space in case I want to expand it to a few galaxies or even start with a big bang?

Basically what I am asking is how can I make this like a universe?

View Replies View Related

Draw V-shape Of Height N Entered By User With Stars

Apr 12, 2014

Am stuck in a problem that asks to write a program using nested for loops to draw a V-shape of height "n" entered by the user with stars .

View Replies View Related

Adding Stars After Each Item In The List - For Loop Isn't Working?

Feb 26, 2014

This is supposed to be a method that adds stars after each item in the list.

Java Code:

import java.util.ArrayList;
public class ClientProgram {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("the");

[Code] ...

I'm guessing it's because list.size() changes, though but it should only find that value in the beginning, so it shouldn't be a problem?

View Replies View Related

Update Sequence Of Stars According To Actual English Word And Guess Character

Jan 12, 2014

Below is part Two the method I need creating:

This method updates the sequence of stars according to the actual English word and the guess character.

public static String updateSecretWord(String secretWord, String englishWord, String guessedChar)
{
}

Below is the example of how it should look like when I call it

updateSecretWord(“*****”, “Hello”, “h”) = h****
updateSecretWord(“h****”, “Hello”, “o”) = h***o
updateSecretWord(“he**o”, “Hello”, “e”) = he**o

View Replies View Related

Make A Program With Two Buttons

Feb 10, 2014

I'm trying to make a program with two buttons... when you click the first a label shows a red square when you click the second it shows a green square... right now i have the imageicons as a comment because when they weren't a comment and i ran the program i saw nothing... the same thing happens when i add label2 to panel3.

Java Code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GUI3{
public static void main(String[] args){
//frame
JFrame frame = new JFrame("Test");

[code]...

View Replies View Related

How To Make A Program Run Multiple Times

May 18, 2014

I have made a basic math game that asks you questions and tells you if you have answered them correctly or incorrectly. The game runs great! The thing is that it asks you a question one time and after you answer you have to run the program again. I want to get the program to ask ten questions. After that I want to figure out a scoring system for it but the first step is to get it to ask my ten questions. Here is my code.

package pkgnew;
import java.util.Scanner;
import java.util.Random;
public class New {
public static void main(String args[]) {

[Code] .....

View Replies View Related

Take Grades Program And Make A Class

Jul 17, 2014

where to create the array of chars that hold the letter grade. I am assuming that would be in the main with the other arrays. Passing it into an object creating a method in the record.java. Then displaying it in my main.

Take the Grades program and make a class. An object that hold 5 student names, an array of 5 chars that hold the letter grades, 5 arrays of four doubles each to hold the set of test scores. The class should have methods that return a specific student's name, average test score and a letter grade based on the average. Demonstrate the class in a program that allows the user to enter each student's name and their 4 tests scores. It should then display each student's average and letter grade.This is my main program:

import java.util.Scanner;
public class GradeBook{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
Record[] students = {new Record(), new Record(), new Record(), new Record(), new Record()};
for(int j=0; j < 5; j++){

[code]....

View Replies View Related

How To Make Paint Program Not Error Out

Oct 14, 2013

I am screwing around with mouse listeners so i decided to make a basic paint program. It works fine but when it draws more than 100 circles it errors out. i know why its doing it (its because i set the array to 100) but my question is how to make it so it has not limit in the array.

Here is the code

public class PaintProject extends Applet {
int numClicks = 100;
int numCicles;
int xCoord[];
int yCoord[];
boolean paint;

[Code] .....

View Replies View Related

Make A Simple Calculator Program

Mar 11, 2015

i am working on my assignment in Compro 2, we are ask to make a simple calculator program

here's my code;

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.BorderLayout;

[code]...

View Replies View Related

How To Make A Program That Gives Exact Change

Sep 4, 2014

So obviously I'm new to java and i need to write a program that gives exact change in quarters, dimes, nickels, and pennies. For some reason it seems to work correctly but the nickels never is correct and I'm not sure why, seeing as though everything else is.

Java Code:

public class Coins{
private int c;
public Coins(int coins){
c = coins;
}
public void calculate(){
int quarters = c / 25;

[Code] .....

View Replies View Related

How To Make A Simple Connect Four Program Without GUI

Nov 19, 2014

My code below is trying to make a connect four program without GUI. I'm having trouble with getting the players to make their moves. What should I put in my "makeAMove" method...

Java Code:

public class Connect

final static int MAXROW = 6;
final static int MAXCOL = 7;
public static void main(String[] args){

[code]....

View Replies View Related

Program In Java - How To Make It Less Procedural And More OOP

Mar 1, 2015

Any tips on how i can improve this simple resource calculator for this game called Clan of Clans.

It might even look more functional than OOP.

import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ClashOfClan {
private static String[] units = {"Barbarians ", "Archers ",
"Giants ", "Goblins ", "Wall Breakers ", "Balloons ",

[Code] .....

View Replies View Related

Make Simple Program Which Takes In Argument?

May 12, 2015

So I'm trying to make a simple program which takes in an argument (target) and then looks through an ArrayList of strings. If it finds a string that begins with (target) then it will return the index of that string. If it doesn't find a string which begins with (target) then it will return -1 instead.

For some reason, the program is always returning -1, rather than the index of the string within the ArrayList when there is one which matches the search criteria.

Here is the code:

public int getIndex(ArrayList<String> text, String target)
{
int i = 0;
int index = -1;
boolean found = false;

[Code].....

View Replies View Related

How To Make The Program Understand 10 Number System

Oct 24, 2014

I want to create a program where i can output a number. ex. 3452 And the program will output 3000: three thousand 5: five 53: fifty-three

How can i make the program understand the 10-number system?

View Replies View Related

Make Program That Declare Largest And Smallest Out Of Three Numbers?

Jan 13, 2015

how can i make a program that declare the largest and smallest out of three numbers??

/*
* To change this license header, choose License Headers in Project Properties.
int a;
int b;
int c;

[Code]....

View Replies View Related

Make A Program Which Take Input From Keyboard And Count Numbers

Sep 12, 2014

import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int number;
System.out.println("Input a number");

[code]....

What i want to do is that if the number is greater than 50 to count until 100. else if the number is less than fifty to count for example from 36 to zero.

View Replies View Related

How To Make Hangman Program Work For Phrases With More Than One Word

Apr 13, 2015

I created the following hangman program, but it only works for one word file inputs. How can I modify the program to make it work for files with a multiple word phrase?

/**This program is a basic Hangman game. It takes a word or phrase from a file, and then asks the user to guess the letters in it. The program ends when the user inputs 8 wrong guesses.
*/

import java.util.Scanner;
import java.io.*;
 public class hangman{
public static void main (String[] args) throws FileNotFoundException{
  Scanner kb = new Scanner(System.in);
  String guess;

[Code] ....

View Replies View Related

How To Make A Program That Determines The Highest Value Out Of Inputted Numbers

Sep 14, 2014

how to make a program that determines the highest value out of the inputted numbers.

View Replies View Related

Make A Java Program That Calls Object Value Initialized

Feb 23, 2014

i have this following codes and im trying to make a java program that calls an object value initialized.

public class TestClass
{
public String name;
public int age;
public void myMessage()
{
System.out.println("Hello I'm" + name + "and i'm" + age + "years old");
}
}

what i want is to put the following codes of the object.. so once i compile and run the project it executes the value of an object from the method i defined above.

TestClass myName = new TestClass();
myName.name = "Jefferson";
myName.age = 18;

my question is, it is possible to declare or define it in the same project? or i need to do this separately?

View Replies View Related

Make Program That Tells User To Type Sentence?

May 21, 2014

Ok, so I have to make a program that tells the user to type a sentence and at the end of the sentence a "." must be put to end the program. If a "." period is not entered, it must re-prompt the user to enter a period. On top of all this, the program has to count the number of letters in the sentence. I cant seem to get the while loop working and I cant find anywhere how to make a counter count the number of letters.

import java.io.*;
class Sentence
//The purpose of this program is to

[Code]....

View Replies View Related

Writing A Program To Make A Tic Tac Toe Game Utilizing Inheritance

May 7, 2014

I am new to programming and we are writing a program to make a tic tac toe game utilizing inheritance, client-supplier, arrays, and EventButton. I am still trying to wrap my head around events and inheritance. We are instructed to write 4 classes (a TicTacToeModel, a TicTacToeView, a TicTacToe Controller, and a TicTacToeButton). I got the TicTacToeModel down, but am having trouble with the other classes.

Instructions for View: Write a class that implements the UML class diagram below. The only purpose of this class is to draw a picture of the specified TicTacToeModel. For purposes of this assignment, we understand a ‘theme’ to include such things as the background color of the tic‐tac‐toe board, the shape and color of the X indicator and the shape and color of the O indicator. While you are free to select your own personalized ‘theme’ your TicTacToeComponent must always be proportionally ‘correct’ regardless of the client‐determined width and height of the Component.

Instructions for the Controller: Write a controller that controls the game. There is one human player (the X player) and the computer player (the O player). The name of the class must be TicTacToeController. In a sense, the controller is the game since the controller will

1) create a TicTacToeModel
2) create a TicTacToeView and
3) create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game. While you are free to change the appearance of the controller, the basic elements must be provided

These are our instructions for the TicTacToeButton: create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game.And this is the code I have thus far for the button:

import java.awt.event.*;
import java.awt.*;
public class TicTacToeButton extends EventButton{
public TicTacToeButton(int x, int y, int w, int h) {
super("Move");
setBounds(x, y, w, h);

[code]....

View Replies View Related







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