Hello, I'm trying to make a very basic + - calculator in java using constructors after watching thenewboston video tutorial I tried to experiment with it. My litle project is almost finished my only problem is that the boolean I use is being reset after I assign it. If someone could take a look at I would really appriciate it. Also ignore the names of the class didn't bother to change it after the tutorial video. package bucky; public class tuna { private double num1; private double num2; private double awnser; public boolean plus; public tuna(double numbr1,double numbr2){ num1 = …

Member Avatar
Member Avatar
+0 forum 2

Hello I cant figure out how to recive a boolean from a method in another class. public boolean arYatzy() { boolean yatzy = true; for (int i = 0; i < tarn.length - 1; i++) { yatzy = yatzy && (tarn[i] == tarn[i + 1]); } if (yatzy) { return true; } else { return false; } } public static void main(String[] args){ Yatzy y2 = new Yatzy(); int[] t2 = new int[5]; int ggr=0; int antal=0; System.out.println("loop"); boolean varv = true; long startTid = System.currentTimeMillis(); do{ for(int i=0; i < t2.length; i++) { t2[i] = 1 + (int) ((6 …

Member Avatar
Member Avatar
+0 forum 5

Does anyone know a good way to force javascript to evaluate all operands in a boolean expression? In particular, what I am tring to do is essentially this: return isValid(a) && isValid(b) && isValid(c); while this technically does work, the function is responsible for highlighting invalid areas on the form for user attention. Since the `&&` operator short circuits, it will only ever highlight the first invalid expression, possibly requiring the user to go through several rounds of correcting input data. Any ideas?

Member Avatar
Member Avatar
+0 forum 2

Im trying to create a deck of cards using enums. I already have my enum declared, but I'm stuck in how exactly to create the deck of cards using a boolean array. So far i tried to initialize my constructor, but I don't know what direction to take now. Any help would be greatly appreciated it. Thank you. package Cards; //Class to represent a standard Deck of 52 Playing-Cards // The following functionality is provided // Default Constructor - creates a complete deck of cards // shuffle() - collects all 52 cards into the deck // deal() - returns a …

Member Avatar
Member Avatar
+0 forum 6

Hi, I have a program that deals with stacks and queues in python. Part of the program compares items in 3 stacks that contain objects. The loop will run and compare all items in the top of the stacks and pop the item that has the highest value and appends to a queue. The problem I am haveing right now is the best way to set up my conditional while loop to have the block of code keep running untill all 3 stacks are empty of objects. Currently the loop ends as soon as one of the stacks become empty …

Member Avatar
Member Avatar
+0 forum 3

#include<iostream> using namespace std; #include<string> #define INT_MAX 100000 #define INT_MIN 0 using namespace std; class Automobile { public: Automobile(); void read(); bool is_cheaper_than(??????) const; bool better_mileage_than(???????) const; bool better_finanace_than(??????) const; void print() const; private: string name; float price; float mileage; float finance; }; Automobile::Automobile() { name=" "; price=INT_MIN; mileage=INT_MAX; } void Automobile::read() { cout<<"Model name:"; cin>>name; cout<<"price"; cin>>price; cout<<"miles per gallon:"; cin>>mileage; cout<<"percent financing:"; cin>>finance; } bool Automobile::is_cheaper_than(?????) const { ??????????? } bool Automobile::better_mileage_than(?????) const { ???????? } bool Automobile::better_finance_than(?????) const { ??????? } void Automobile::print() const { cout<<"Model:" << name<<"\n" <<"price:" << price<<"\n" <<"Miles Per Gallon:" << finance<<"\n" <<"Financing:"<<"\n"; …

Member Avatar
Member Avatar
+0 forum 7

I am working on a practice exam right now and I came across a write-your-own code problem that I can't figure out. The question is: > Modify your first function. In addition to returning the greatest value by pass-by-value, you should also sent a true/false value back to main() if the values are the same. Hint: waht variable type would hold a true/false value? How does this value need to be sent to main? The first function they speak of is: double greatest (double value1, double value2){ if (value1 > value2){ return(value1); } else { return(value2); } } Oh, and …

Member Avatar
Member Avatar
+0 forum 6

I have a Sudoku puzzle and I need to make sure that each row and column have each number 1 through 9. What is the easiest way of doing this? The code snippet that I have so far is below. public static boolean rowsAreValid(int[][] array){ for(int i = 0; i < array.length; i++){ for (int j=0;j<array.length;j++){ This is my Sudoku puzzle. Note that I also need to do the same for each 3x3 section. Your help is greatly appreciated! 3 8 4 2 1 6 9 7 5 9 7 1 8 5 4 3 2 6 5 2 6 …

Member Avatar
Member Avatar
+0 forum 4

The assignment requires program to read from a file into an array, use two boolean functions to validate certain data (set to "true" when there are no errors) then output any errors to a separate file. Everything works fine except for validating the rate. All the numbers are read into the array correctly and the calculation seems sound (works correctly on a calculator) but for some reason the calculation in C++ always results in 0 which makes EVERY record output an error. PLEASE HELP, it is driving me CRAZY :twisted: (the "cout" lines were inserted just so I could see …

Member Avatar
Member Avatar
+0 forum 4

[CODE]class Date { private int day, month, year; // the date Date(int d, int m, int y){ day = d; month = m; year = y; } Date(){ }; void get() { day = Console.readInt(); month = Console.readInt(); year = Console.readInt(); } void put(){ System.out.println(day + "/" + month + "/" + year); private int elapsedDays() { // The number of days elapsed from 1/1/1900 to this date int days = (year-1900)*365+(year-1901)/4; int k = 1; while (k<month) { int daysInMonth; if (k==9||k==4||k==6||k==11) daysInMonth = 30; else if (k==2) { if (year%4==0 && year!=1900) daysInMonth = 29; else daysInMonth = …

Member Avatar
Member Avatar
+0 forum 5

Hi this is my first post, but I've lurked for a while usually finding answers to my questions in other threads, I couldn't find this one so I broke my posting cherry to ask. I know I'm missing something, probably really simple, but possibly I'm doing this completely wrong. I'm trying to write a method that determines if a year is a leap year and then returns it to main to print out whether it's a leap year or not, after I get this working I'm going to modify it so that it runs in a loop until the user …

Member Avatar
Member Avatar
+0 forum 5

For some people it may be difficult to understand what Boolean is.Well, it's a type of algebra. We will be learning about three Boolean operators today-AND,OR,NOT The order for evaluating Boolean operators are as follows:- AND-If you have a code that should be executed if two conditions are true, you use the and operator.And is shown as [U]&&[/U] in C++.1 && 0 will evaluate to 0 because one of them is false. OR-Same as and, but either or both of the conditions must be true.Or is shown as [U]||[/U] in C++.1 || 0 will evaluate to 1 since one of …

Member Avatar
Member Avatar
+0 forum 2

My program generates a list of random or pseudo random numbers between a certain range specified by the user through the console. My problem is when the user, or in this case myself, tries to generate a random number list specified by entering true(1) in the console the output is always false(0). I cant seem to figure this out. Any help would be great. The program has four files. utility.h just contains all the include statements, filer.h, filer.cpp has the code to make the file of random numbers, and test.cpp has the main function to test the code with the …

Member Avatar
Member Avatar
+0 forum 3

the following program is to print all possible sum combinations of a number for example 6=1+5,2+4,3+3,1+1+4,1+2+3 12=3+9,4+8,5+7,.......,1+1+2+3+5 but i m not getting any output...maybe there's a problem with proper ending of loops pls help[CODE]import java.io.*; public class sumpermutations { public void main()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int input,i,j,d=0,s=0,num=0,d1=0; System.out.println("ENTER NUMBER"); input=Integer.parseInt(br.readLine()); for(i=1;i<=99999;i++)//for loop till the highest 5 digit number { while(i!=0)//to find the sum of digits of each number { num=i; d=i%10; s+=d; i/=10; } if(s==input)//checks if the sum is equal to the input number { if(istrue(num))//function to check if the digits of num are in ascending order …

Member Avatar
Member Avatar
+0 forum 11

hello this is my first C++ program my problem is that i cant find out to things frist is that when i rune it and sett the mathe type it is ignored laiter and hit shows alle offe the posbole mathe types ( that i have enterd +,-,/ and * ) secone prolem is that if i try to multiply or divid whitt 0 my system crashes, i see that it is a math problem for the pc or somthing butt i have no idd how to fix it. i was thing som sorrt of program that maksi it so …

Member Avatar
Member Avatar
+0 forum 2

print "Hello, World!" ;) Hi, everyone, Venku (a.k.a Python Newb) here. I just kind of randomly opened up Python today (I do that a lot), and I decided I would finally ask this: What does the "is" statement do in Python 2.7.1 (if the ver# matters)? I checked out the Python command line (used "help()" "modules" "is"), but it only gave a comparison to C and an unintelligible description of what it does. I have an extensive vocabulary, and I am great with grammar and spelling, but the [I]terminology,[/I] like "collection" and "membership" confused me. It appears to be used …

Member Avatar
Member Avatar
+0 forum 3

Hello, So I have a .txt file which is kind of built like: N 1234554321 Joe Jones Y 1234555432 Sarah Clark Y 1234321231 Kirah Williams N 1234212321 John Johnston The output, line by line, as the txt file is, and it works and all, I output "Y" or "N" I store "numbers" in an ans[] array and I call the name using string name; getline (inFile, name); cout << name; However, I do not know how to make an error statement for if Y 1233420321 Sally James to print like Y 1233423321 Sally James *** one variable changed to 3 …

Member Avatar
Member Avatar
+0 forum 1

I am currently writing a program in which you input a word and the program then outputs all of the different ways the characters can be moved round into anagrams. I have wrote a way of turning the command line argument into a char array using the toCharArray() now I need to write a boolean array to see if the character has been used before. Any help?

Member Avatar
Member Avatar
+0 forum 6

i have this code, i need to have [B]for()[/B] inside this boolean method, but it shows an error that return method is missing. how can i solve it? [CODE] public static boolean findPrevious(int dataIdx, int featIdx, String data, String[][] array){ for(int i=0; i<dataIdx; i++) { if(array[i][featIdx] == data) return false; else return true; } } [/CODE] thanks ^^

Member Avatar
Member Avatar
+0 forum 6

I'm trying to write a method that draws a rectangle. If the user enters height = 4, and width = 8, and the print of character " * ", then the left rectangle is drawn on the left if the filled flag is true. If the flag is false, then version on the right is drawn which would be an empty rectangle. * * * * * * * * ||||| * * * * * * * * * * * * * * * * ||||| *e m p t y * * * * * * * …

Member Avatar
Member Avatar
+0 forum 12

The problem for my CMPT103 class is to write a program that takes a binary number as an integer and returns it as a decimal, i would be able to do this easily by taking it as a charecter array and dealing with each individual element but i dont understand how to do this. my teacher gave us 3 functions we have to use and a descrption of what theyre supposed to do: • bool convertBin(int &binary); This function will take an integer value that is in binary and change it to a decimal value. In the event that the …

Member Avatar
Member Avatar
+0 forum 4

Hi, I'm a student of Java, and my first homework assignment is more advanced than our reading. So...I'm lost. This question is: Q5: Write a program that reads a list of exam scores from the keyboard. Using A=90 to 100, B=80 to 89, C=70 to 79, D=60 to 69 and F=0-59 compute: (i)The total number of students, (ii) the numbers for various grades, (iii) the percentage of total number of students for each letter grade, (iv) the range of scores for each letter grade and (v) the average score for each grade as well as for (vi) the entire class. …

Member Avatar
Member Avatar
+0 forum 4

Hello, I'm a student working on my first hands-on assignment. One of the questions is this: Q4: Write a program that converts a user input temperature from degree Celsius to Fahrenheit or Fahrenheit to Celsius using: C = 5 (F -32)/9 or F = 9C/5 + 32 The user must input temperature with a ‘c’ or ‘f’ (case insensitive) after the number and the program should output the corresponding value. If any other letter, is used, print an error. [10] This is what I have so far, but it's returning 7 errors - one of them being "enum types must …

Member Avatar
Member Avatar
+0 forum 3

3. Consider the Boolean expression F(A,B,C) = ABC + A'C' + A'B'. (a) Using the laws of Boolean algebra, derive an expression that uses only AND and NOT operators. (b) Using the laws of Boolean algebra, derive an expression that uses only OR and NOT operators. First, I am sorry for my poor grammar. :'( I have tried every laws I could find and still couldn't solve it, heres 1 example of what I have done: ABC + A'C' + A'B' = ABC + A'C'(B + B') + A'B'(C+C') = ABC + A'C'B + A'B'C' + A'B'C + A'B'C' = …

Member Avatar
Member Avatar
+0 forum 10

Hello, I have a question about the code below [CODE] // Checks the vertex a if (this.a != ((Triangle)o).a) { return false; } [/CODE] So In a method called Triangle i declared an instance variable like this: [CODE] private java.awt.Point a [/CODE] What I think this code is doing is that this.a is comparing its point value (a.x and a.y) and checking to see if they are equal to that of the o Triangle point (o.a.x and o.a.y) is my interpretation correct?

Member Avatar
Member Avatar
+0 forum 1

so i'm created a program that display the name and grade of students from a file, and also a boolean that checks to see if the names are in alphabetical order. The problem is that i've created a files that has a name in alphabetical order but it still returns false [CODE]class Assignment { //------------------------------------------------------------------------------ public static void main (String [] args) throws Exception { Scanner kb = new Scanner(System.in); System.out.print("\nEnter name of a file of Students: "); String filename = kb.nextLine(); Section sec = new Section(filename); System.out.println("\nIn forward order:"); sec.print(System.out); System.out.println("\nhasNamesAscending() --> " + sec.hasNamesAscending()); } //------------------------------------------------------------------------------ } // …

Member Avatar
Member Avatar
+0 forum 2

[B]Edit: that was my mistake. i placed the codes in wrong line. i solved it by myself already. thanks for viewing.[/B]

Member Avatar
Member Avatar
+0 forum 3

The last time I was making a program, I wanted to input from user a boolean answer (to save space ;)) An input of 0/1 works good (0-false) and (1-true), but if the user inputs the boolean values as "true" and "false", it comes out to be an error. So, are there any ways of doing so.? I believe, that the strings "true" and "false" are defines using #define in the header files because of which the input is creating an error. Am i correct.?

Member Avatar
Member Avatar
+0 forum 5

I have this method to see whether not the year is a leap year or not. heres the code i get the error missing return statement at the end. What can i do , i can't add return true or return false, becuase that screws it up. public boolean isLeapYear() { if(years % 4 == 0) { if(years % 100 == 0) { if( years % 400 == 0) return true; else return false; } } else return false; }

Member Avatar
Member Avatar
+0 forum 5

YO, I would be EXTREMELY grateful if someone can help me out with some boolean method stuff. I have this assignment where we've been building up this bank account project thing, and at the moment I've been asked to put in a boolean method called inBalance that returns true if the balance is in credit. I thought I had this down but I'm getting an error saying 'missing return statement'. I also need to put something in called canWithdraw that prevents money being drawn if there's enough in the balance, and with that one I don't even know where to …

Member Avatar
Member Avatar
+0 forum 8

The End.