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
ADVERTISEMENT
Oct 6, 2014
write a program using nested switch case to show the different shops in a shopping mall.
View Replies
View Related
Mar 30, 2014
why this switch code does not work for the 'Q'. Everything works fine for the other cases, i.e. 1,2,3, and 'q', but when I type in 'Q', I get the default case. Please note all the values have been defined in an earlier part of the code but for simplicity's sake I have removed them below
do {
switch (choix) {
//demande le nombre de patons a achete
case '1':
[Code].....
View Replies
View Related
Jul 10, 2014
can give me a sample program which solves with switch case statement with nested if inside?
View Replies
View Related
Oct 9, 2014
How do i check INT range for switch case: ?
int grade = 68;
switch (grade) {
case 100:
System. out.println( "You got an A. Great job!" );
break;
case 80:
System. out.println( "You got a B. Good work!");
break;
[code]....
View Replies
View Related
Mar 1, 2015
If I have an integer variable like int a=9 then in the switch case If i write
switch(a) {
case 4+a: System.out.println("hii");
}
Then why is this statement a compile-time error that variables cannot be used inside a case statement why does the compiler not subtitutes the values in place of the variables.
So basically what problem it creates for which the language developers did not include it as a proper syntax,is there any reason behimd this because of jump table?
View Replies
View Related
May 19, 2014
I am stuck with two switch statements that I feel I am close to achieving. My first switch statement is to generate random mathematical operators for the math questions in the game (generated randomly) My second switch statement is to determines which action the system will take upon the correct or incorrect answer. For the first switch statement I have a variable called num. Num is a random integer. I have an operator mapped to each outcome of num. In my second switch statement I am trying to use the variable answer as a variable in the first case but do not know how.
package pkgnew;
import java.util.Scanner;
import java.util.Random;
public class New {
public static void main(String args[]) {
//Declare and construct variables
[Code] ....
View Replies
View Related
Sep 10, 2014
In switch case statement string expression whether it will work or not ???
View Replies
View Related
Apr 25, 2015
I am trying to make GPA calculator. I decided to use only switch statement and make it as simple as possible. The point is to enter as many classes and students as user wants. I keep getting credit points 0 at the end and also text format is not good too. Here is the code.
import java.util.Scanner;
import java.io.*;
public class SwitchExercise{
public static void main(String[] args) {
String grade = "";
String grades="";
String coursename="";
String headingleft="COURSES";
[code]....
View Replies
View Related
Jun 19, 2014
So from what iv learnt in Java and programming in general is that using a case statement is far more efficient that using multiple IF statements. I have an multiple IF statements contained within a method of my program, and would like to instead use a case statement.
public String checkPasswordStrength(String passw) {
int strengthCount=0;
String strengthWord = "";
String[] partialRegexChecks = { ".*[a-z]+.*", // lower
".*[A-Z]+.*", // upper
".*[d]+.*", // digits
".*[@#$%!]+.*" // symbols
[code].....
View Replies
View Related
Sep 19, 2014
//Program prompts user for today's day (0-6) and a number for future date.
import java.util.Scanner;
public class FindFutureDates
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
[code]...
I was thinking of a second string for futureDate to print after: "the future day is " line.
View Replies
View Related
Dec 3, 2014
We're told to make a cash register program for 5 products using Java. It loops until "-1" is entered on the "Continue?" input dialog box.There should be a:
1. Main Menu - where the user will pick what to buy (one product at a time) like the sample code below and prompt the user if he will buy another product or not. If yes, the program will go back to the main menu to buy another product and if not, continue to the program. And it looks something like this: LEvFOwQ.png
2. Receipt - at the end of every transaction.
3. Daily Sales Report where it shows all receipts then grand total like:
Transaction 1
-subtotal
Transaction 2
-subtotal
and so on then,
GRAND TOTAL
4. Inventory Report where it shows the Items Available before the Selling, Items Sold, and Items Available after Selling in table format.
Below is the code for a simple cash register for only one product that I made but I need to upgrade it for it to work for 5 products. That code will serve as the basis for this program.make the switch or if-else statement for the main menu first and if I got it right I try doing the rest.
int userQty1 = Integer.parseInt(JOptionPane.showInputDialog(
"Product ID Product Name Product Quantity Product Price"
+prodID1 + " " +prodName1 + " " + prodQty1 + " " +prodPrice1 "
"
+ and so on until prod5));
[code].....
View Replies
View Related
Oct 5, 2014
Write a program using switch statement to allow users to choose an item of a menu. For example, the menu looks like the following.
File menu
1. Open
2. Close
3. Save
4. Exit
Enter your choice:
If you type 1, then your program should print out "Open is selected" (double quotes not included).
Notice:
(1) Using Scanner to get user choice;
(2) If the number user input is not in {1,2,3,4}, your program should let user know that.
Here's what I have:
public static void main (String[] args) {
int user = 1
switch (1) {
case value: 1
System.out.println ("Open is selected");
[Code] .....
View Replies
View Related
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
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
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
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
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
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
View Related
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
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
May 23, 2015
After the executing the code below:-
class Test
{
public static void main(String [] args)
{
String s = new String("new") ;
String d = new String("new") ;
System.out.println((s==d)+ " "+s.equals(d)) ;
System.out.println(s==d + " "+ s.equals(d)) ;
}
}
OUTPUT:- false true
false
Why did the output change in the second print statement?
View Replies
View Related
Oct 4, 2014
I'm trying to create a simple java math question quiz using random operators, but keep sinking myself into deeper despair. The numbers must range from 0-9 and given an operator: +,-,/,*,%. Can't create a new method or use Case statements. The code isn't finished but don't want to make it any worse.
package marco;
import java.util.Scanner;
import java.util.Random;
public class Project {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
Random rand = new Random();
System.out.println("How many questions do you want?");
[code]...
View Replies
View Related
Jul 17, 2014
I have one template.xhtml file at /template/template.xhtml
<h:head>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="100">
<h:outputText value="header"></h:outputText>
</p:layoutUnit>
<p:layoutUnit position="center">
[Code] ....
I am getting the following exception because of the **ui include** tag in template.xhtml. Is the src attribute of ui include is wrong.:
javax.faces.FacesException: Could not resolve NavigationCase for outcome: index
at org.primefaces.renderkit.OutcomeTargetRenderer.getTargetURL(OutcomeTargetRenderer.java:86)
at org.primefaces.component.menu.BaseMenuRenderer.encodeMenuItem(BaseMenuRenderer.java:162)
at org.primefaces.component.tabmenu.TabMenuRenderer.encodeItem(TabMenuRenderer.java:89)
[Code] ....
View Replies
View Related
Oct 17, 2014
If my file name is MyBigXMLFile.xml it won't delete but if I rename it to mybigxmlfile.xml it will delete. How do you get around the case sensitive issue?
View Replies
View Related
Oct 15, 2014
I have 2 strings
String value ="/abc_12_1/abc234/abc/filename.txt";
String src="abc"
Sring tgt=xyz
Now I have to replace the string in variable value in case of exact match; I am trying to do the following :
if(value.contains(src)
{
value.replaceall(src,tgt);
}
Now the problem here is it replaces all the occurrence of abc in the string value and I get the below output as :
value=""/xyz_12_1/xyz234/xyz/filename.txt";
However my requirement is only in the case the value exactly matches with source the replacement shd happen. I am expecting the output like this :
String value ="/abc_12_1/abc234/xyz/filename.txt";
Also the above code is in a function which will be called multiple times and the values will keep on changing. However the target and source will remain the same always.
View Replies
View Related