Calculator Program - Use Strings And Methods To Include Arrays

Jul 23, 2014

My assignment is to essentially update a calculator program that uses strings, and methods, to include arrays. How to create and call an array that the user defines the size of and then inputs the numbers to fill the array. Here's the example my prof gave us of what the output should look like:

Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Dot product
6. Generate random array
7. Quit

What would you like to do? 1

How many values are in the arrays? 3

Enter the values in the first array, separated by spaces:
2 4 6

Enter the values in the second array, separated by spaces:
1 3 5

The result is [3.0, 7.0, 11.0]

How to create an array that would allow the user to define the size of the array and then inputs the values for the array? I'm completely lost. I never should have taken java as an online class.

View Replies


ADVERTISEMENT

Console Calculator Program - How To Split Array Of Strings

Apr 22, 2015

I'm writing a command line application of a calculator in Java. I need to be able to (as per program requirements) split the array of strings (6+3) into an array of strings? How would that be done? I know you can use the split method, but I am not really sure how that wold work to perform math with them?

On a side note: for this application, how could you make the program accept a variety of different lengths of strings to perform math with them?

View Replies View Related

Slot Machine Program Using Methods And Arrays

Nov 13, 2014

I am designing a program that generates 3 random numbers from 1-5 and if 2 match, the user wins $1. If 3 match, the user wins respectively:

All 1s - $5
2s - $10
3s - $25
4s - $50
5s - $100

I first used a loop to run until the user runs out of money or wishes to stop. Then I made 2 methods. 1 to generate the random numbers and 1 to see if the user won any money. I am storing the random numbers in an array called slotnumber.

This is what I have so far but I am getting compiling errors at while (cont == 'y') {

import java.util.Scanner;
import java.util.Random;
public class SlotMachine
{

[Code]......

View Replies View Related

Methods And Arrays Slot Machine Program Won't Compile

Nov 19, 2014

Here are the errors I am getting:

SlotMachine.java:21: error: illegal start of expression
public static void getNums(int [] slots)
^
SlotMachine.java:21: error: illegal start of expression
public static void getNums(int [] slots)

[code]....

i keep fixing small things and cannot get it to compile. Below is the original code,

import java.util.Scanner;
import java.util.Random;
public class SlotMachine
{
public static void main (String args[]) {
int userMoney;
Scanner input = new Scanner(System.in);
System.out.print("How much money to start with?

[code]....

View Replies View Related

Design Layout Of Calculator And Add One More Button To Clear Textbox Strings One By One

Mar 30, 2014

I need to design the layout of this calculator and also add one more button that clears textbox strings one by one instead of whole.

import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.event.*;
public class Calculator extends JFrame{
double value1;
double value2;
String operator;
double result;

[Code] .....

View Replies View Related

Arrays / Strings And Related Output Arena

Apr 3, 2014

This is one of the most interesting programmes in java Number-Word..The programme give the alphabet output of a no. inserted between 1 and 10,000

Example :

Input:Enter a word less than 10000

5457

Output:Five Thousand Four Hundred And Fifty Seven

Code:--

import java.util.*;

Java Code:

class num2word
{
public static void main(String args [])
{
num2word ob = new num2word();
ob.check();
}
void check ()

[code]...

View Replies View Related

Passing Strings In Methods

Mar 16, 2014

I am trying to call stringToFile in the main method but it throws error saying "incompatible types scanner cannot be converted to string."
 
public static void main(String[] args) {
Scanner keyboard = new Scanner (System.in);
mask(keyboard);
printingString();
fileName(keyboard);
  String completeFileName = stringToFile(keyboard);

[Code] ....

View Replies View Related

Arrays Outside Of Methods

Aug 22, 2014

I'm working on a side project, which will eventually hopefully be a Pokedex, and I've just been going to it at the end of every chapter and using the stuff I've learned to work on it.So I just read chapter 3, which is all about variables and teaches how to use arrays.

my question is, does an array have to be declared inside a method? Because I'm trying to create an array inside a class without any methods and without the main, and I continuously get errors. Here's a quick working of my code that won't compile.

class blah {
blah a[] = new blah[7];
a[0] = new blah();
}

The error message focuses on a[0] = new blah(); Telling me the 0 should be a ], the = is an illegal start of type, so on and so forth. The program compiles completely fine if it's within a method, like this:

class blah {
void a() {
blah a[] = new blah[7];
a[0] = new blah();

}

}

Or if I have public static void main (String[]args); But I'm trying to practice working outside of main.So does an array have to be within a method,

View Replies View Related

Using Double Dimensions Strings And Methods

Apr 17, 2015

i have to use a if loop. I just started using methods and loops..You have been hired as a software developer for Canada’s customs - Toronto Pearson International Airport. Your job is to develop part of the Canada Passport System. The Database Administrator has forwarded to you the database for all the Canadians. For simplicity, assume you only have five records (i.e., only five people on file). These fixed records are the following:

First name, Last name, SIN, Last Date of Entry to Canada, Number of Entries
Mike beee 4567 12-12-1999 7
Jessie weree 4444 07-07-2007 1
Liza veee 2121 05-05-2013 2
Zico qeeee 2444 Never left the country 0

the two dimensional array stores all the values. In addition, all these values should be of type String.The Canadian officer can always see the following four choices:

1) Show custom’s database,
2)Update custom’s database,
3) A summary of a passenger’s record, and
4) Exit.

Choice 1 : always allows the officer to see all the database records (i.e., the five records). Each of these records consists of the following: First Name, Last Name, SIN, Last Date of Entry to Canada, and the Number of Entries (i.e., see the above stored values).

Choice 2 : allows the officer to update the database whenever one of the five Canadian passengers arrives. Once the officer chooses this option, the system will ask him/her for the SIN of the passenger. Then the system will ask for today’s date (i.e., the recent entry date). The system will then reflect those changes on the console screen and the number of entries will be increased by one.

Choice 3: summarizes the record for one passenger where his/her first and last names and last date of entry to Canada will be shown. The last date of entry should only have the last four digits (i.e., only the year). To extract those digits, you should use the String’s method(s). However,before a record is summarized, the records of all Canadians should be shown on the screen in order to allow the officer to choose among those records. Choice 4 allows the officer to exit from the system completely; otherwise the list of choices should be always shown on his/her monitor.This is the code i have so far.

import java.util.Scanner;
public class QuestionFive{
public static void main(String[] args) {

double passportInput;
Scanner sc = new Scanner(System.in);
// public static int generalList() // to show the list of choices and return the chosen option
//
// public static void updateRecords(int recordSize, String[][] passportDataBase) //to update the records
//

[code]....

View Replies View Related

Error When Using Arrays And Methods

Jan 4, 2015

I am receiving one error when using arrays and methods. It's at the bottom of the code and I have commented what the error is .

import java.io.*;
import javax.swing.*;
public class CEO_PROGRAM_PartB
{
public static void main (String[] args) throws IOException

[code]....

View Replies View Related

Creating Methods Using Arrays - Fraction Class

Sep 27, 2014

I am trying to get the average of 3 different fraction arrays. I made a fraction class and I made methods such as read() and average() in this new class.

package fractions;
import java.util.Scanner;
import java.util.Arrays;
public class FractionArrays {
public static void main(String[] args) {
Fraction completeFraction = new Fraction(5,6);

[Code] ....

I was wondering if there was any way to use the arrays I created in the read method in the average method. If I find that out I should be able to do it on my own. Is there a way to make the arrays public to use in different methods?

View Replies View Related

Write A Class Named Calculator Add Four Methods To That Class

Jan 30, 2014

Write a class named Calculator add four methods to that class:

add(int a, int b)
sub(int a, int b)
mul(int a, int b)
div(int a, int b)

Then write a Tester class with main function and show the use of the methods in Calculator class..

View Replies View Related

Grade Calculator Program

Nov 12, 2014

how to I modify my program so that it asks the user how many studens are in the class then according to the value the user inputs that is how many times the program will ask the user for a grade. Once the graded are entered it will then output the class average, minimum, and maximum. I believe that you'd use a for loop yet I am troubled.

import java.util.Scanner;
public class GetLetterGrade{
public static void main(String [] args){
Scanner reader = new Scanner(System.in);

[code]...

View Replies View Related

Grading Calculator In Java Program?

Sep 26, 2014

i have a similar problem but what i need to do is to detect an exused absent of which in my notepad is represented by 00 and 0 being an unexcused absent, anyway if a student has an excused absent example a quiz for that day will be deducted from the total quizzes example if i was the teacher and had 2 quizzes of 10 items each and she was absent in one of the quizes instead of let say her score was 9 on the first quiz it should go 9/10 and if it was an unexcused absent 9+0/20 anyway this is my java code and notepad example

import java.io.*;
import java.util.*;
import java.lang.*; 
public class GradingSystem {
public static void main (String[] args) throws FileNotFoundException

[code]...

View Replies View Related

Program Calculator Using Switch Case

Oct 14, 2014

I am making a programme for a calculator to - Divide, multiply, add and subtract. I have the code written but when I am running it and trying to add it was for some subtracting ....

import javax.swing.JOptionPane;
public class calculator3 {
public static void main(String[] args){
String number1,number2,operatorstring;
double result=0,a,b;

[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

Calculator Program - Using Decimal And Operators

Oct 20, 2014

How do I get the code to use decimals? Also whenever you input 1, 2 or 3 as one of the operators, it always does that operator as well as the 4th operator at the end. So it always does subtraction. However when you use 4 as the only operator it works perfect.

import java.util.Scanner;
public class Program05 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
 double left;
double right;
 
[Code] ......

View Replies View Related

Carpet Calculator Program With Aggregations?

Nov 26, 2014

I'm doing a Carpet Calculator Program with aggregations and can't seem to get my RoomCarpet class to work properly. This is what I have so far:

package roomDimensions;
/*
*
* Raul Caltenco

[Code].....

View Replies View Related

Program That Asks To Create 2 Arrays

Oct 24, 2014

I'm just learning about arrays. I have a small program to write that asks to create 2 arrays. One holding 5 names of flowers. One holding the prices of those 5 flowers. I ask the user what kind of flower they want and the quantity. I then need to create a loop that locates the flower name and uses that index to find the cost of the flower. I am struggling on how to write in code how to use one array index to find another. Example: Roses and $.50.

View Replies View Related

Sieve Of Eratosthenes Program Using Arrays

Feb 9, 2015

I am trying to figure out the Sieve of Eratosthenes program using arrays. I am trying to display the prime numbers of 1-100. My code right now is:

import java.text.DecimalFormat;
import java.util.Scanner;
public class TextLab06st
{
public static void main(String args[])
{
// This main method needs additions for the 100 point version.
Scanner input = new Scanner(System.in);
System.out.println("
TextLab06

[code]...

I am getting the error <identifier? expected for the line "primes.[index] = false;"

View Replies View Related

Calculator Program - Print Heart Rate Ranges And User Information

Jan 26, 2014

I am attempting to make a heart rate calculator program. Here is a little overview of what I am trying to do. It must use a constructor and get and set methods. It must print heart rate ranges and the user's information(age).

// Use scanner to get inputs
import java.util.Scanner;
 
// Declare class
public class HeartRates {
private int Age;
private int DayOfBirth;
private int MonthOfBirth;
private int YearOfBirth;
private double MaxHeartRate;
private double MinTargetHeartRate;

[Code] ....

View Replies View Related

Java Program - Asking User For Two Strings And Using Duplicate Function

Jul 4, 2014

Am i doing this right?

public class TwoStrings
{
public static String duplicate (String s) {
String t = s + s;
return t;

[Code] ....

View Replies View Related

Creating Palindrome Program - Arrays And For Statements?

Feb 14, 2015

I am trying to create a program that reads a sentence, such as: "abba is running to the radar" scans this sentence, and then prints out all the palindromes. I am running into issues with my arrays and for statements. Here is my code:

static String palindrome, backwardsLower,
palindromeLower, palindromeClean, backwards2, backwards = "";
static String[] words;
static int counter;
public static void main(String[] args) {
palindrome = JOptionPane.showInputDialog("Please enter a phrase. " +

[Code] ...

I am aware that there is a few "useless" variables in there at the moment, I will clean them up (as well as some useless statements, I see those too). The issue comes at about line 17. The variable backwards REMOVES all the spaces from the array, so when it comes time to compare the strings, it is comparing individual words to the ENTIRE string, thus no words will ever be a palindrome.

View Replies View Related

Test Values Stored In 2D Arrays - Program Keeps Looping

Jan 13, 2014

I am trying to test values stored in 2d arrays once but i my program just keeps looping what am i doing wrong

Java Code:

tempi=i;
tempx=x;
for( i=0;i<3;i++) {
for( x=0;x<4;x++) {
if(rounded[i][x]<395 || rounded[i][x] >405) {
System.out.println("there is an error with probes "+rounded[i][x]);

[Code] .....

View Replies View Related

Gradebook Program - Calculate Averages Of 25 Students Using 2D Arrays

Apr 16, 2014

I am making a gradebook program that calculates the averages of 25 students using 2D arrays in which the students have four test grades. I have figured out how to display the averages of each student in one column but I cant seem to figure out how to display the letter grade of the average into another column.

Right now my program reads from a .txt doc

Heres what I've got.

TestGradeBook.java

import java.util.*;
import java.io.*;
public class TestGradeBook {
public static void main (String [] args ) throws IOException{
//Declarations
final int ROWS = 100;
final int TESTS = 4;

[Code] .....

GradeBook_Data.txt
Name100100100100
// basic name and grades

View Replies View Related

Unable To Create A Program For Class Using Two Dimensional Arrays

Dec 6, 2014

I am trying to create a program for class the uses two dimensional arrays. I am stuck on the second step that states Use two parallel arrays. One is a two-dimensional array -- a row of this array will hold six values in this order: [0] number of hours worked, [1] hourly pay rate, [2] gross pay, [3] net pay, [4] federal withholding, and [5] state withholding.

This is what I have so far:

Java Code:

double [][] data = new double [30][6];
String [] names = new String [30];
String str = null;
String detail = null;
int n = input(data, names, inputFile); mh_sh_highlight_all('java');
(there's more but i don't believe it pertains to this question)

My question is how would I create this array. Or, is that right above? I've searched online and in my book and I just don't understand.

View Replies View Related







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