Car Rental Program - Display User Who Spent Maximum And Minimum Rent
Apr 22, 2015
I am working on this rental program and got stuck in the last part. The program is about renting a car; after completing the rent process it displays the user who spent maximum and minimum rent. This is where I can't proceed. The program displays maximum values for both max and min. Here's the code I have written:
import java.util.Scanner; // program uses Scanner
public class CarRentalTest {
public static void main( String[] args )
{
System.out.println("Welcome to Rental Portal");
Scanner input = new Scanner( System.in ); // create Scanner to obtain input from command window
CarRental details=new CarRental();
So I'm learning java from a website and I was tasked with creating a simple program which allows the user to enter a series of integers, then finally when they decide to input a non-integer the program will print the maximum and minimum values of the integers they entered. So for example if they entered 5, 4, 3 and 2 then enter a non-integer the program would output 5 (maximum value), then 2 on a new line (minimum value).
Here is my code:
import java.util.Scanner; public class MaxMinPrinter { public static void main(String[] args) { Scanner in = new Scanner(System.in); int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE;
[Code] ....
And this is what the output looks like:
Actual output ------------------------------------------- Enter an integer: 5 - 10 - - Enter an integer: -4 - 8 - -6 - - Enter an integer: 11 - -1 - - Enter an integer: q - -1 - -6
When it's supposed to look like this:
Expected output ------------------------------------------- Enter an integer: 5 Enter an integer: 10 Enter an integer: -4 Enter an integer: 8 Enter an integer: -6 Enter an integer: 11 Enter an integer: -1 Enter an integer: q 11 -6
i need to calculate the minimum and the maximum, actually it seems to be easy but, the minimum should be the smallest number but 0..this is my code
Java Code:
Scanner s = new Scanner (System.in); int max = 0 ; int min = 0 ; System.out.println(" Please enter 3-5 numbers"); int a = s.nextInt(); int b = s.nextInt(); int c = s.nextInt(); int d = s.nextInt(); int e = s.nextInt();
I am doing a homework assignment for a class I'm taking and writing a java program that finds the smallest and largest number in an array entered by the user. For some reason no matter what I enter as the smallest number it returns 0 as the smallest. I'm not sure what I have done wrong. Here is my code:
import javax.swing.JOptionPane; public class MinimumAndMaximumJamesBulow { public static void main(String[] args) { int minimum = 0; int maximum = 0;
I am trying to write a TreeMap that can hold a max of 20 colors and a minimum of 8. I have a while loop using pollLastEntry to limit the max but I can't figure out how to set the minimum. The hex number is the map's key and the color name is the value. I tried to use entrySet() and iterator to just double the size of the map but map can't have multiple keys with the same value. It also seems that to set a minimum would require some kind of further input(which I'm trying to avoid) of colors and their hex numbers.
//Method to hard code the colors into the map public TreeMap<String, String> cm() { //Color Map <Hex number, Color name> //Uses a TreeMap to keep all the colors organized by key TreeMap<String, String> cMap = new TreeMap<String, String>(); cMap.put("FFFF00", " Yellow");
1. Create a program that will return the maximum and minimum numbers in the elements of ONE-dimensional integer array. Save it as MaxMin_OneDim.java
2. Create a program that will return the maximum and minimum numbers in the elements of each row in a TWO-dimensional integer array. Save it as MaxMin_TwoDim.java
3. Write a program PrintPattern which prompt a user to enter a number and prints the following patterns using nested loops (assumed user entered number is 8 output is:)
1 .... 87654321
12 .... 7654321
123 .... 654321
1234 .... 54321
12345 .... 4321
123456 .... 321
1234567 .... 21
12345678 .... 1
(Without the dots, i just put them to give spaces)
I have been having difficulty with the weeks concepts in my online Java class, the program is to be as followed:
For this exercise you will implement a class called Pair, that represents a pair of two numbers.The Pair class should include the following constructor and methods:
CONSTRUCTORS public Pair(double num1, double num2) -- Creates an object that represents a pair of double values
METHODS
public double getAverage() -- Returns the average value of the two numbers public double getDistance() -- Returns the absolute vale of the distance between the two numbers public double getMaximum() -- Returns the maximum value of the two numbers public double getMinimum() -- Returns the minimum vale of the two numbers
Write a class called PairTest that tests your Pair implementation. The PairTest should prompt the user for the two values, create a Pair object with the values and then print the average, distance, maximum, and minimum of the pair. The input / output should look like the following:
Enter the first number: 5.5 Enter the second number: 3.0
NOTE: For this exercise, your solution should not use any conditional statements. Instead you should use the methods provided by thejava.util.Math.
So far I have:
import java.lang.Math; import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner in = new Scanner(System.in); { System.out.println("Please enter a value for the first number");
I am trying to write a program that asks the user to enter a number from 1 through 10 and then the program will display the roman numeral for that number.
I am also adding a error message in which i haven't yet because im still trying to figure out how to the program will do the roman numeral.'
I have used the if and else if. but when i input a number it just repeats the number back to me.
The program cimpiles but it doesn't do what i want. here is what i have so far. how can i get the program to display the roman numeral after the number is entered.
import javax.swing.JOptionPane; public class Romannumeral { public static void main(String[] args) { double number;
I finished a game in Java and sent it to a friend. Launching the program in my computer worked just fine.
But he got this error : "Could not find the main classs: Main. program will exit"
My JRE version is the most updated one. His JRE was version 1.6. He updated his JRE, and the problem was solved.
This is a bit worrying for me, because as far as I know, 1.6 isn't a very old version of the JRE. It's not the most recent one, but not that old.
This is worrying because I'm planning on sending my game to a lot of friends, and trying to distribute it on the internet.
A lot of people don't have the most updated JRE. And they are mostly non-programmers, so I can't expect them to update to the newest version of Java upon downloading my game. They might not know what Java is, even though they got it on their computer, and upon receiving an error, they'll just give up on the game.
If my game wouldn't work with a significantly old JRE, that would be reasonable. It's part of the nature of working with Java. But the fact that a relatively updated JRE, 1.6, doesn't work with my game, is worrying.
*(Please note: My game isn't implementing anything "special". Swing and KeyBindings are the 'newest' additions to Java that I can think of inside my game)*.
In short, I'd like to know that my game works on most of the computers it tries to run on. Knowing that it doesn't work on a relatively new JRE, is worrying.
So I have two questions:
1. Is it normal, for a Java program, to have such "high" demands for the JRE version? Do a lot of Java games demand at least version 1.6 of the JRE? Is this common?
2. How can I find out the minimum JRE version requirement for my program? Is there a methodical way to do this, or do I just have to go through all the libraries I use in my game and figure out what's the JRE release version for each one?
I'm required to create a program that finds the minimum value in an Array of integers.
Here is my approach :
public class Person { public static void main(String [ ] args){ int theArray[]=new int [10]; int result = 0; for (int i:theArray){ if (i < Integer.MAX_VALUE)
[Code]...
I can't really progress from this position. I keep getting told to change the return type to int on main method, then when i do it says change it to void..
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'm trying to make a stock program that stops the user from entering in textfield and displays a message when stock is low. There's just 2 problem the entered value by the user is only decremented twice then the total stock resets for example with SofaTotal and the if statement doesn't work:
Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".
I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.
public class PrimeNumber { Scanner scan = new Scanner(System.in); int userNum; String neg;
I'm using the JOptionPane to display and receive information to/from the user. In addition to this, I am using StringBuilder to receive inputs from the user and then manipulate (append) that input to display the desired output.
//Example
(JOptionPane): "Enter text" (user input): Java is cool! (program): *stringBuilder.append(" I love it!") JOptionPane.showMessageDialog( ); .....
Psuedo-like code. The problem is that showMessageDialog(null, string) and not showMessageDialog(string, string). I want to display the enter text: " Java is cool! I love it! " in the JOptionPane. How do I accomplish this, since showMessageDialog only accepts (null, string).
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();
Implement an applet that display historical facts. The applet will include facts from october 28 to december 4th to test the applet.
What is the best thing to add text in my GUI - JLabel, JTextArea? I am trying to display different words on my csFacts. Once a user click button yesterday and button tomorrow?
public class Facts extends JFrame implements ActionListener{ private JButton button1,button2; private JPanel panel; private JLabel label; TextField ri = new TextField(50); private void createGUI(){ setDefaultCloseOperation(EXIT_ON_CLOSE);
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 am using a GUI to display search results based on user's input server name. I am using MS Access as DB and I have the DSN set up correctly.But the search results are displayed for the first typed value in text filed. I am getting same result set every time though i input different server names .
import java.sql.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.DefaultTableModel; public class SearchResult implements ActionListener{
URL....So the problem is that when I type in "PA" it will display about 24 Zips and Populations before it stops. The problem is in the ZIPs file. It goes down the list and then takes the Zip from the Zips file to the Zips in the Population file and displays the Population. It will go to population 513 and stop. Reason being, there is no ZIP code in the Population file to display a population. The loop then stops. How can I get the program to skip over the zip code when there is no corresponding ZIP code in the other file and continue showing the other Pops..Here's what I currently have completed:
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Population { //Declaring global variables. Scanner fileScannerZip, fileScannerPop, inputFile; private String lineZip, linePop; int invalidZip;
As a part-time student, you took two courses last term. Write a Java program that calculates and displays your grade point average (GPA) for the term. Your program should prompt the user to enter the grade and credit hours for each course. This information should then be displayed with the lowest grade first, and the GPA for the term should be calculated and displayed. A warning message should be printed if the GPA is less 2.0 and a congratulatory message if the GPA is 3.5 or above.
I am trying to create a GUI with already existing code. My assignment is: Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the GUI should display the value of the entire inventory, the additional attribute, and the restocking fee.
Where to start. The text book does not cover a GUI that displays this type of information rather it just displays graphics. I would like to create a separate class that holds the GUI information just to make everything flow better. I have provided my current code below:
Java Code:
// ProductTest.java // by JakeB public class ProductTest { // main method begins public static void main(String[] args) // begin main { myGUI display = new myGUI(); display.setVisible(true);
[Code] .....
This is all I have for the GUI. I am at a total loss and I am behind 2 weeks now. I cannot move forward until I am able to get this done and the class ends next week.