Program Will Not Calculate Or Print Out Intersection And Difference
Nov 19, 2014
I have to use methods and loops to code this program. Cannot use any java set or any built in java shortcuts!
import java.util.Scanner;
public class setPractice {
public static Scanner kbd;
public static final int MAXSIZE = 20;
public static void main(String[] args) {
kbd = new Scanner(System.in);
[Code] .....
This is the input I put in my code and this is the output:
How many numbers will be in the 1st set: 3
Enter list of integers for 1st set:
34
2
56
The ascending order for 1st is:
2
34
56
How many numbers will be in the 2nd set: 4
Enter list of integers for 2nd set:
56
2
33
6
The ascending order for the 2nd set is:
2
6
33
56
The intersection of the two sets is: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
As part of the instructions we are required to use loops and methods to solve to program this code. We are not allowed to use any set functions that are already built in java.The methods for intersection and difference MUST return int value.
import java.util.Scanner; public class setPractice { public static Scanner kbd; public static final int MAXSIZE = 20; public static void main(String[] args) { kbd = new Scanner(System.in);
I'm trying to print out the results of a program that calculates the number of seats the parties will get in an election.I have to print the partial results and the national results.
I can print te number of seats per party in each constituency, but how can i sum all seats per party in each constituency and print the national results?I'm working with vectors, which I know it might not be the best option, but everything is working, except the fact that I can't loop throuhg the vector and retrieve the total sum per party.Like, adding the seats for labour party in Constituency A and B and C, etc, and print the sum. And do the same for conservative party.Is it possible, or doIhave to create a method in Parties class to solve the problem?
This is what I have now.
for (Parties p : h.geral) { show += String.format("Constituency - %5s - %5s - %d%n", p.getConstituency(), p.getParty(), p.getNum_seats()); }
import java.util.Scanner; public class Bill { public static void main(String[] args) { Scanner console = new Scanner(System.in); //final variables Premium Service final double monthlyChargeP = 25.00; final double FordayminutesP = 0.10;
[Code] ....
I can't find the syntax on {} my block is highlighted red in my application
I have been tasked with creating an invoice (school assignment). Part of the calculations is creating an interest depending on the amount of days between the current date entered, and invoice date entered (The program prompts the user to enter both the current and invoice dates by asking for the day, month and year).
We are also supposed to set the contructor to a default date of 1/1/1900.. but I don't know how or where to code that.
How to calculate the difference between the CurrentDate and Invoice. I have displayed the dates to the user as follows.
I need to create a simple Java program that calculates the difference between two entered days of the week with the following requirements:
-Ask the user to enter in a day of the week by name (e.g. Monday) - Ask the user to enter in another day of the week by name (e.g. Friday) - Create a static method other than main that takes in two Strings as input, and returns an integer value equal to the difference between the two days - Use an array with the days of the week in it to find each entered in day of the week, and use their indices to calculate the difference - Output the difference for the user to see
Create a program to input the length and width of a rectangle and calculate and print the perimeter and area of the rectangle. To do this you will need to write a Rectangle class and a separate runner class. Your program should include instance variables, constructors, an area method, a perimeter method, a toString method, accessor and mutator methods, and user input. Your runner class should include 3 Rectangle objects. One default rectangle, one coded rectangle, and one user input rectangle. All methods should be tested in the runner class.
This is my code:
import java.util.Scanner; public class Rectangle { double length; double width; public Rectangle() {
[Code] ...
What have I done??? I have created this program using the few different resources with which I am supplied, but I don't understand the resources.
We had to use these methods with the given parameters and code them correctly. We cannot use any built in java methods for sets.
import java.util.Scanner; public class setPractice { public static Scanner kbd; public static final int MAXSIZE = 20; public static void main(String[] args) { kbd = new Scanner(System.in); int[] setA = new int[MAXSIZE]; int[] setB = new int[MAXSIZE]; int[] intersect = new int[MAXSIZE];
[Code] ....
This is the input given to the program:
How many numbers will be in the 1st set: 3 Enter list of integers for 1st set: 12 3 2
The ascending order for 1st is: 2 3 12
How many numbers will be in the 2nd set: 4
Enter list of integers for 2nd set: 2 3 6 1
The ascending order for the 2nd set is: 1 2 3 6
The intersection of the two sets is: 0 0 0 //Program not correctly print intersection of two sets
The difference of A-B is: //Program is not printing the difference either...
My code is like follows. I want add the lines of data from text file to arraylist.After add the lines to array list,i want to get the interesection between the lines of data. But I could not get the intersection and it returns empty. My sample data from specific line in text file as follows,
how does the program know to calculate for only one year?
public class Interest2 { public static void main(String[] args) { double principal; // The value of the investment. double rate; // The annual interest rate. double interest; // The interest earned during the year.
I have spent the past 12 hours on it and have gotten no where. I need to create a program that will calculate different tax brackets. I have tried all combinations I can think of and can't get it to work!!! I am literally about to go insane! I need the program to calculate tax will be 1% for anything up to $50000. If the tax is over $50000, you keep that 1% of $50000 and then add the remaining. So for an income in the second range, it would be 1% of $50000, and then 2% of (income - $50000). This then continues for each range.
The problem I'm having is getting it to display the correct interest rates. I am not asking for you to write it for me. I want to learn. But at this point I have exhausted all resources available to me.
import java.util.Scanner; public class Project3taxinfo { public static void main(String[] args) { final double RATE1 = 0.01; //1% tax on the first $50,000 final double RATE2 = 0.02; //2% tax on the amount over $50,000 up to $75,000 final double RATE3 = 0.03; //3% tax on the amount over $75,000 up to $100,000 final double RATE4 = 0.04; //4% tax on the amount over $100,000 up to $250,000 final double RATE5 = 0.05; //5% tax on the amount over $250,000 up to $500,000 final double RATE6 = 0.06; //6% tax on the amount over $500,000
I'm starting with my version of very basic program: calculating area of circle. And of course it doesn't get well. My question: what is wrong in this code?
public class circleAre{ double radious; void putData(double radi){ radi = radious;
I am having a problem with my program. I can't get my program to calculate properly. Everything compiles and run but its just giving me a wrong answer. I am suposse to get 115.50 but instead I am getting .30...
order.java public class Order { double salesTaxRate; //initializing a variable for the sales tax rate. double subTotal; //initializing a varliable for the sub total. double shippingCost; //initializing a variable for shipping cost. double salesTax; //initializing a variable for sales tax. double totalCost; // initializing a variable for totale cost.
Assume the tanker is a cylinder of length 19.35 feet and volume 1320 gallons. What is the diameter in feet of the tanker truck? To solve this problem, write a Java program to calculate the diameter. For full credit, your Java application must follow these specifications.
1. The program must interactively input the capacity of the tanker in gallons and its length in feet. This should be done in the main method of your Tester class.
2. The input data should then be used to construct a TankerTruck object. You will need to write the TankerTruck class.
3. A TankerTruck method should be used by main to calculate the resulting diameter of the truck in feet.
4. Your program should use the standard Java constant for the math constant PI.
5. The output should be displayed using fixed-point notation, rounding to one decimal place of precision
import java.util.Scanner; public class SophiaKeyProgram1 { public static void main(String[] args) { // TODO Auto-generated method stub int numQuarter; //number of quarters in a year double rainfall=0; //the amount of rain
Write method distance, which calculates the distance between two points (x1, y1) and (x2, y2). All numbers and returned values should be of type double. Incorporate this method into an program that enable the user to enter the coordinates of the points, then calculate and display the distance by calling the method –distance.
I've tried numerous times to make it work and I'm on the right path, however I'm missing some things in the code to make my results look like this later on, which I've attached onto this post.
write a program that calculates the change due to a customer by denomination; that is, how many pennies, nickels, dimes, etc. are needed in change. The input is to be purchase price and the size of the bill tendered by the customer($100, $50, $20, $10, $5, $1).
having some trouble doing this. Here are the requirements:
1)Write a program using loop and break to calculate the value of PI. 2)You can use the following equation to calculate PI. PI=4/1-4/3+4/5-4/7+4/9-4/11+4/13 etc.. The program shouldn't loop until the criteria is satisfied. 3)The criteria is the value of PI you get is very close to the “real” value (3.1415926), meaning that their difference should be smaller than a very small numeric number, e.g., 0.0001). 4)The control structures you may need for this program are loop, if-else, and unlabeled break. 5)The output should have the format: for each iteration, it has iteration number and the corresponding value of PI until that iteration. The last line would be the final value of PI.
Here is my code so far:
package ids; public class IDS { public static void main(String[] args) { double pi = 0; for(int i=1; i<=100000; i++){ if ((i%2)==0){ pi+=(4/(2*i-1));
I want to Write a program that calculates the minimum fixed monthly payment needed in order pay off a credit card balance.
the Amount is 3,500 the annual rate is 9.9%, the minimum payment is 2% a month. the fixed payment is 150.
By a fixed monthly payment, we mean a single number which does not change each month, but instead is a constant amount that will be paid each month.
The program should print out :
payment information: new balance total ....... current payment due .......
if you make minimum payment (2%) you will pay of in .... months and you Will end up paying an estimated total of $........
if you make the fixed rate payment, you will pay of in .... months and you Will end up paying an estimated total of $........ and you will save $........
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
You are to write a parallel program that will receive a large array of unsorted integers containing digits from 0 to 99. The program will have to calculate the SUM and AVERAGE of ODD number digits between 25 and 75 (inclusive). The user may specify the size or the array and the total processor that the machine has. The size of the array must be divisible by number of processor. Based on the given size, the computer will generate random integer numbers automatically to populate the array.
The program should display the status of the calculation for each processor. The result should be displayed after all calculations are completed.Error messages should be displayed appropriately
a) Write a sequential (non-parallel) program that will accomplish above task. b) Write a concurrent (parallel) program that will produce the result of the above task.
I just created a program to calculate the roots for a 2. degree equation, When I first created my program, I defined the r1 and r2 as double, but got an error saying they needed to be defined as String, why is that?When should I be using string? I am new to java and I have mostly only used int, double and Boolean so far.
import java.util.Scanner; import java.text.DecimalFormat; public class c3e1 { public static void main(String[]args){