User Should Be Able To Enter Amount Of Digits Array Should Be Shifted Left
Nov 6, 2014
This is the other code problem I have. The user should be able to enter the amount of digits the array should be shifted left. For example, if the user entered 3 and the array was 1 2 3 4 then it should return 4 1 2 3. here is my code.
public char[] replaced(char[] array, char oldChar, char newChar) {
char myFun[] = new char[array.length];
for (int i = 0; array.length > i; i++) {
myFun[i] = array[i];
so I had to make a program that prompts the user to enter a loan amount and the years for the loan and I have the conversions and everything my only issue is that when the chart pops up it just looks like a bunch of numbers and its missing the column headers
for example
Interest Rate Monthly Payment Total Payment
import java.util.Scanner; public class InterestRate { public static void main(String[] args) { double monthlypayment = 0; double totalpayment = 0; Scanner input = new Scanner(System.in); System.out.println("Enter Loan Amount");
Goal is to: Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.
First I don't know where I made mistakes here, and the only error it finds right now is that str2 was not initialized and I cannot figure out where/when to initialize it.
import javax.swing.JOptionPane; public class DigitsAndSum { public static void main (String[] args) { String str1; String str2; int int1 = 0; int int2 = 0;
Create an application that allows a user to enter values for an array of seven Salesperson objects. Offer the user the choice of displaying the objects in order by either ID number or sales value.
import java.util.*; public class SalesPersonSort { public static void main(String args[]) { int[] id = new int[7]; int[] salesValue = new int[7]; final int END = 999;
I am starting a program that is dealing with arrays. My issue, allowing a user to enter 'x' number of people into an array. How do I first allow them to enter the size of an array, and then enter strings (list) into that array. In addition to this, I need to specify the number of boxes of cookies sold by each person and keep a tally of the number of people selling cookies in each category (e.g. 1-10, 11-20...etc). Instead of having a number 100000, I want the user to enter that size, 'x'.
import java.util.Scanner; public class cookie { public static void main(String[] args) { Scanner input = new Scanner(System.in); int x = 100; double saleCount[] = new double [x]; String[] girlScout = new String[100000];
package question.pkg3; import java.util.Scanner; public class Question3 { public static void main(String[] args) { // TODO code application logic here Scanner Luka=new Scanner(System.in); double sum=0;double count=0; int[] a=new int[10];
[code]....
I'm required to write a program that allows the user to enter up to 10 integer grades into an array. Stop the loop by typing in ‐1. Your main method should call an Average method that returns the average of the grades.I There's something wrong with my program , the count always stays 0 and the sum is always 1 less than the actual sum.Sample input and output :
Enter grade 1: 8 Enter grade 2: 9 Enter grade 3: 10 Enter grade 4: 5 Enter grade 5: 8 Enter grade 6: 9 Enter grade 7: -1 output
Average grade is 8.1666666667On line 13 I had count=count+1 ;
{ public static void main (String []args) { Scanner numberin = new Scanner (System.in); double store [];
[Code]....
How would I get my program to display a * for every 100 dollars in sales that the user enters in so: for example the user enters in store 1: $ 400 in sales for the store I want it to display store 1:****
The first part of my code allows the user to enter in whatever values the stores have in sales. The Second half of the code starts at line 19 is my best guess on what I need to do I just am not sure how to get it to display what I need it to.
I Have been playing with this for while, and I can not seem to get my head around, how I can do this. I need to get the last two digits of a year that a user will enter. For example, a date like July 2 , 2014, I want to get the last two digits of year 2014 which are "14" and divide it by 4. This will give me 3.5; how ever I will disregard the ".5" and just keep the 14. I have no problem doing the division, my biggest this is how to just get the last two digits of a year. This is what I have so far, it is basically a template of how I want my program; I just need getting the last 2 digits of a year.
public class DateCalc { public static void main (String[] args) { String month; int day; int year;
[Code] ....
" This will give me 3.5; how ever I will disregard the ".5" and just keep the 14 ". I meant that I just want to keep the 3 from the 3.5 that will be generated when you divide 14 by 4.
I've four classes object. I don't know how to display the amount paid by the user, and show the balance. The calculate button just show the total amount. Do I have to create another object class? And I've to show the bills too.
This is my 1st Frame
import javax.swing.*; import java.awt.*; //titlepanel class displays a title in a panel public class TitlePanel extends JPanel { public TitlePanel() { JLabel title = new JLabel();
I have returned with yet another problem but I think this one might be a bit easier to fix.
So the whole MO of this program is to take user input, and display the sum of the digits of the number they entered. I am supposed to do this by utilizing methods. So far this is what I have and when I compile it tells me that it "cannot find symbol", which I don't understand as I define what "m" is in the for loop. The other error is that it says:
"Exercise6_2.java:22: error: incompatible types: possible lossy conversion from long to int return result; ^
I don't understand why it's giving me this error nor do I understand why result seems to inherently be an int. (Also the public static int sumDigits(long n) method was given to me by the book so that is what I am supposed to use).
import java.util.Scanner; public class Exercise6_2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a integer"); long n = input.nextLong();
I created my own class and it basically randomizes the amount of 'spells' [magic] a user uses (range 1-5). I can't figure out how to increment the initial randomized output to make something like this :
User X : uses 2 spell. User Y : uses 3 spells.
User X : uses 3 spells. (Taking the randomized 2 and increment by 1) User Y : uses 4 spells. (Taking the randomized 3 and increment by 1)
My current setup looks like this : First one is the class I created and the second one is just how the output would look like. (seperate by +++++...)
My goal is to create a METHOD to increment it.
public class Spell { // Max number of spells private final int MAX_FACE_VALUE = 5; // Current face value private int faceValue; // New instance of Spell public Spell() { faceValue = 1;
[Code] ....
+++++++++++++++++++++++++++++++++
public class SpellOutput { public static void main(String[] args) { //Object creation Spell spellCasterOne = new Spell(); Spell spellCasterTwo = new Spell(); Spell spellCasterThree = new Spell();
Write a program that reads from the user an integer and reduce it by multiplying its non-zero digits. The result of the multiplication is a number which is to be reduced as the initial one. This process continues until an integer of one single digit is obtained. For example:
Your program should display the number obtained in every iteration.
Sample run1 Enter an integer: 64734502 After iteration 1: 20160 After iteration 2: 12 After iteration 3: 2
Sample run2 Enter an integer: 97737999 After iteration 1: 6751269 After iteration 2: 22680 After iteration 3: 192 After iteration 4: 18 After iteration 5: 8
Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.
Now I have a code for spacing out the integers, and I have a separate code for adding the digits. But I am not sure how to merge them together. Both of them work independently
Spacing code: import java.util.*; public class SumoftheIntegers { static Scanner console=new Scanner(System.in); public static void main(String []args) { int num1, test, rem; int counter = 0;
[Code]...
Now the sum of the integers code:
import java.util.Scanner; public class sum { public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in); // Enter amount System.out.print("Enter an integer: "); int integer = input.nextInt();
I am writing a program for a game. It is between the user and a virtual player. The game starts with a pool of consecutive integers 1-100. The size of the pool is based on a random generated number at the beginning of the game. At the start, both players' scores are 0. For each turn, the player picks one number from the pool. That value is added to the player's score, the computer gets the sum of all the remaining numbers in the pool that divide evenly into the player's pick. The player's pick and its divisors are then removed from the pool.
The player should be able to play the game as many times as she wants without ending the program. Instructions should appear on the screen only once at the start of the program.
For each turn, both players' current score, the current pool of numbers, and a prompt for a number to be entered should show onscreen. I have written the code until I get to the function that updates the pool of numbers after a turn.
import java.util.Scanner; import java.util.Random; public class SlickPick { public static void main (String[] args){ Scanner read = new Scanner(System.in); int []pool = new int[100];
[Code] ....
My thinking is that I need to use the binary search to find the indexes of the divisors array and then use those indexes as the start values. I'm not sure how to assign the divisors indexes to start. Do I need an array for start? Whenever I run the program, the only value missing is 3.
//Name : poolUpdate //Description : This function modifies the contents of the pool as a result of a turn of play. //Parameters : The pool array, the divisors array, the size, and the user's pick. // : //Return : public static void poolUpdate(int[] pool, int[] divisors, int size, int pick){ int low=0; int high=size-1;
I have a simple java program to write which tells the user combination of coins that equals to the amount of change i.e:
user input 87
output:
3 quarters 1 dime 0 nickels 2 pennies
How the program remembers the remainder which is passed to the next column of let say dime
i.e
originalAmount = amount; quarters = amount /25; amount = amount % 25; <---- this is confusing for me?!?! how can the integer = integer % 25 dimes = amount / 10; <--- HOW THE PROGRAM remembers the "remainder" instead of the original user input as the code it self tells you dimes = amount where "amount" is what user input NOT remainder.
amount = amount % 10; so on ....;
What I don't understand is HOW this algorithm works. I mean we have int amount where user inputs the number we get the first calculation amount/25 = how many quarters and then amount %25 WILL tell us about the reminder. By looking at this piece of code I would say that the system should start the calculation for the dimes again from the original number since the code says dimes = amount/10 AND amount = amount%10. My understanding is that the calculation should be done from the original user input.
Book or code it self is not clear for me how the reminder is "REMEMBERED" and then pass on to the next calculation>!?!?
UNLESS the code: amount=amount%25 gets the remainder so the next code under it is REQUIRED to read from the last prompt code.
I'm currently taking a Java Programming module in college, the program we are using is jGrasp and I'm currently stuck on one aspect of the language.
I did VB last year and I enjoyed it and got good grades so I'm comfortable with Java in terms of compiling the code correctly and getting it to run with no errors.
But for a project we got yesterday, the user must be able to enter data (e.g. an answer) into jGrasp without using a GUI. This is the case because we won't be dealing with GUIs until next semester.
I'm able to handle the rest of the project, but the part which I can't figure out is how the user can interact with jGrasp without the aid of a GUI.
I am suppose to design a problem the prompts the user to enter a String. Based on the input from the user, have the program prompt with a full description of the playing card entered. Below is a table of the notation and meaning:
Notation Meaning A Ace 2...10 Card Values J Jack Q Queen K King D Diamonds H Hearts S Spades C Clubs
Use the .charAt(...) to extract each character from the user's input and build a switch statement to determine the full description.
import java.util.Scanner; public class PlayingCardIdentifier { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a card notation: "); String s = input.nextLine();
I am learning Java on my own, and I am creating little programs to do so.The program below asks the user to input text and hit enter. When user does that, it asks if that is correct. If the user enters "y," the program ends. That's good.If the users enters "n," the strGrategul is set to empty which triggers the while statement to start over again. That's good. However, when the program asks the user to "Tell me one thing you are grateful for..." it doesn't wait for user input. Instead it skips to "You said ''? Enter 'y' or 'n'" It thinks the user enter an empty line.
I'm trying to write a program where the user has the option to enter either an int or double but whatever input I enter just gets cast to a double. Do I even have the right Idea by using if else statements?
import java.util.*; public class VS { public static void main(String[] args) { Scanner Input = new Scanner(System.in); System.out.println("Please enter a number"); if (Input.hasNextDouble()) {
so I had to create a program that allows the user to enter a day using a number and then enter a year and after they did that it would create an entire calendar for that year ..so I have that but the only issue is I can not get the numbers to line up neatly.how to do the entire thing in loops, I tried a couple in here..what this would look like as loops instead of switches and cases and if else
import java.util.Scanner; public class Calendar { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);
I have an array made that represents digits and I am trying to make a method so that if there are zeros in front of the first significant digit I want to trim them, I understand you can't re size arrays so I have created a new array, but my code doesn't seem to run correctly? Here is my code I can't figure out what is wrong I've tried everything: (I put stars around the error**)
package music; import java.util.Random; public class Music { private int length; // length of the array private int numOfDigits; // number of actual digits in the array int[] musicArray;
Write a program called ProductCatalog that prompts the user to enter the number of products in the product catalog. The program should then prompt the user for the name and the price of each product in the product catalog. Once all of the products have been entered, the program should output the product information (name and price) of the most expensive product in the catalog. Your solution must use a for loop repetition structure and should use the Product class included in labfiles05.zip to keep track of the product with the highest price. Here is sample output:
Enter the number of products: 3 Enter the name of product 1: iPod Enter the price of product 1: 158.99Enter the name of product 2: iPad Enter the price of product 2: 518.99 Enter the name of product 3: iPadMini Enter the price of product 3: 304.49 Most Expensive: Product [name=iPad, price=518.99]
Your solution should not use an array to keep track of all the product information entered.
I am having trouble with my code, with the For loop and then calling the methods from the Product class into the ProductCatalog. How should I approach this program.
Here is the Product program.
public class Product { private String name; private double price; public Product(String theName, double thePrice) { name = theName; price = thePrice;
[Code]...
Here is the ProductCatalog class where I call the methods from Product class. The For loop is what I am having trouble with as well.
import java.util.Scanner; public class ProductCatalog { public static void main(String[] args) { double number; String product = " "; double productCount = 0;
The exercise sounds like this : Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid , as shown in the following sample run (my code displays correctly the first 9 lines):
The problem is when i input a number greater then 9 as it requires 2 spaces . I m pritty sure i solved it incorrectly or at lost not optimal as i m using a string that decreases on each line to create the pyramid effect.
import java.util.*; public class C5_17 { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Enter the number of lines: ");
I am trying to get a user to enter an integer (registration number) between 500 and 5000. if it is below 500 and over 5000 the user should get a prompt "invalid number" and "non-numeric character". See my code below. it is not working when i enter invalid numbers.
import java.util.*; public class Infomation{ public static void main(String args []) { Scanner in = new Scanner(System.in); System.out.print("Student Number:"); int sn=in.nextInt();
Create a Java application that prompts the user to enter their personal details: First name, last name, gender, address, suburb, postcode, and phone number. Then the program displays all of your personal details to the screen as illustrated. Name the file PersonDetails.jav
package exe import java.util.*; public class Review2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter your full name: "); String name = scanner.next();
[Code]...
If you cant tell straight away how i have stuffed up, what is happening is this;
When i am promoted to enter my name, 'John Smith'. The word 'John' would be stored in the name variable, while 'Smith' is stored under gender, so the next prompt is then 'Whats your address?'
So its only assigning one word per variable, now as far i understand, a string should not work that way. So where is my mistake?
My full instructions are to Design a Java interface called Priority that includes two methods and two constants. The methods are setPriority and getPriority. The constants are MIN_PRIORITY with value 1 and MAX_PRIORITY with value 6. The interface should define a way to establish numeric priority among a set of objects. Design and implement a class called Task that represents a task (such as on a to-do list) that implements the Priority interface. Assume that Task has two attributes (instance data): name and priority. Define the Task constructor to accept and initialize the name of the task. Each newly created Task should have priority equal to MIN_PRIORITY (the constructor should initialize priority to MIN_PRIORITY). Priorities can be changed using setPriority method. Create a driver class TaskDriver that should do the following: prompt the user to enter three tasks and their priorities, and then print the tasks in the order of decreasing priorities. If the user enters an invalid priority that is less than MIN_PRIORITY or greater than MAX_PRIORITY, then the user should be asked to enter priority again until a valid priority value is entered.
So far I have:
public interface Priority { public void setPriority(int level); public int getPriority();