Can't Get Values Found In Switch Statement

Oct 4, 2014

Write a program to calculate sales and visually display. An online Cowboy retailer sells five products whose retail prices are as follows:

Product 1: Cowboy Boots, $74.99
Product 2: Wranglers, $25.99
Product 3: Cowboy Hats, $24.95
Product 4: Chaps, $ 34.89
Product 5: Spurs, $12.50

Write an application that reads the quantity for each product until user has completed their order. Your program should use switch, if, for, while and do while statements to read, calculate and display the total retail value of all pro ducts sold for each user transaction. The user should be able to start a new transaction after the first transaction is completed. The user can make no more than 3 total orders

public class Merchandise {
private int bootsQTY;
private int wranglersQTY;
private int hatsQTY;
private int chapsQTY;

[Code] ....

When I run my program all of my quantities and the total are 0, I have been stuck for a while trying to figure out how to get values assigned to them...

View Replies


ADVERTISEMENT

Method That Returns Non-Numeric Values - Switch Statement

Feb 23, 2014

I am trying to write out a program that takes numerical input from the user and converts it to a date using the English month name. I am experimenting with the method of a "switch" statement without using the "break" clause. However, I seem to be missing something, as Eclipse is telling me I have a syntax error with my block. My curly braces seem properly placed. Also, I made sure to follow guidelines to make my code fit on the screen and remain easy to read.

import acm.program.*;
public class MethodsThatReturnNonNumericValues extends ConsoleProgram {
public void run() {
int month=readInt("Enter month number");
int day=readInt("Enter day");
int year=readInt("Enter year");

[Code] ....

View Replies View Related

How To Turn If Statement Into A Case / Switch Statement

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

Using Switch Statement Inside If Statement

Nov 18, 2014

So I want to make a simple Java that ask the user to pick a powers and it has two options.If the user picks magic then execute the first if statement then ask the user again which type of magic the user wants.I can't make it work it keeps printing the else statement. Why is that?

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

[code]....

View Replies View Related

Way To Incorporate Switch Statement

Apr 10, 2015

this is what code i have so far i want to try and get the computer to output a String type result rather than a number and i wonder if there is a way to output the score after the user is done with the game. I couldn't really see if there was a way to incorporate a switch statement.

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

[code]...

View Replies View Related

Looping Through While Loop With Switch Statement?

Sep 23, 2014

I am having a problem with looping a while loop that contains a switch statement. Here is my code:

package hw4jenningsd;
import javax.swing.*;
public class HW4JenningsD {

[Code].....

View Replies View Related

Can Insert While Loop In Switch Statement?

Dec 8, 2014

I am trying to add a while loop into my switch statement. If you run the program, it will ask to enter the class grade (9,10,11, or 12). If you insert 5, it will say to try again. But, if you enter a wrong number twice, it will continue on to the next part of the program, which is asking how many students are in the class. Therefore, I believe a while loop would work, but it is not working at all. The program still runs, just doesn't fix the error. The program is below:

import java.util.Scanner;
public class stephProject {
public static void main(String[] args) {
//call method
welcomeMessage(); //method 1 of 3

[Code] ....

View Replies View Related

Switch Statement Inside While Loop

May 5, 2015

cannot break from while loop. Whenever I am trying to exit from startCustomerManagement-> backEnd() -> mainScreen()..It gets stuck between mainScreen and backEnd screen. However I can exit from backEnd()->startCustomerManagement() screen

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication19;
import java.io.BufferedReader;

[code]...

View Replies View Related

Modifying ArrayList With Switch Statement

Sep 6, 2014

What I want to happen is to add 2+ contacts by entering "a" from the menu. Then I want to enter "c" and have it display those contacts. But it doesn't seem to remember that I changed the arrayList masterList.

Java Code:

public class ContactListApp2 {
public static void main(String[] args) {
boolean quit = false;
while (quit == false) {
System.out.println("Main Menu:");

[Code] ....

View Replies View Related

Using Variables In Switch Statement Case Clauses

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

Counter Controlled Loop With A Switch Statement

Sep 28, 2014

I'm trying to create a switch statement inside of a counter controlled (while) loop that asks for an input of...

"How many characters would you like to convert?"

Then you type in a number > 0, and then it should convert letters into the "1337" equivalent.

This is an example on what it should do.

How many characters would you like to convert? 5
Enter character #1 to convert: !
!-
Enter character #2 to convert: $
$-
Enter character #3 to convert: #
#-
Enter character #4 to convert: *
*-
Enter character #5 to convert: ,
, -

Whenever i try to run the program, i only get the- How many characters would you like to convert- i input 5 but then nothing else prints..

My codes..

System.out.print ( "How many characters would you like to convert?: " );

int convertCounter = 1;
char ch;
ch = input.next().charAt(0);
while (convertCounter > 0)
switch ( ch ){

[Code] ....

View Replies View Related

Switch Case Statement - String Expression

Sep 10, 2014

In switch case statement string expression whether it will work or not ???

View Replies View Related

Use Switch Or If / Else Statement To Filter Out Data Not Required For App

Feb 21, 2015

I'm using jsoup to parse a calendar page.

I want to use a switch or if/else statement to filter out the data I don't need for the app. This is by no means anything more than a draft because java is easier to work with than android.

Element table = doc.getElementById("launch_calendar");
Iterator<Element> iterate = table.select("td").iterator();
if(iterate.hasNext()){
for(iterate.hasNext();;){
counter++;

[Code] ....

View Replies View Related

Simple GradeBook - Switch Statement To Count A B C D And F Grades

Nov 4, 2014

// GradeBook class uses switch statement to count A, B, C, D and F grades.

import java.util.Scanner;
public class GradeBook
{
private String courseName;
private int total;
private int gradeCounter;
private int aCount;

[Code] .....

Then eclipse told me that:

"Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at chapter5_control_statements_II.GradeBook.inputGrades(GradeBook.java:52)
at chapter5_control_statements_II.GradeBookTest.main(GradeBookTest.java:11)"

View Replies View Related

Switch Statement - Determine Outcomes For Letter Grades

Nov 10, 2014

//Use a Switch statement to determine outcomes for letter grades
switch (Letter)
{
case 'A': outFile.println("
Good Work! You have met the pre-req for CIS 220.");
break;
case 'B': outFile.println("

[Code] ....

is not printing the information on the next line in my output file.

View Replies View Related

Cash Register Program For 5 Products Using Switch Or If Else Statement In Java

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

Writing A Program Using Switch Statement - Allow Users To Choose Item Of A Menu

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

Switch Statement That Decides What Range To Print Based On Letter Grade Input

Nov 1, 2014

Alright so I wrote a switch statement that decides what range to print based on the letter grade input.

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

[code]...

It works fine, but once it the user enters a letter grade and then displays the value, it does not prompt the user for another letter grade so that it can perform the output again. Also if I wanted to display an error message to the user if they enter an invalid letter grade how would I do that. I tried using a while loop and if statement in the switch statement but that didn't work.

View Replies View Related

Using Values That Are Set For Cases In The Switch Operator

Mar 23, 2014

I am new to Java and I am trying to use values that are set for cases in the switch operator.

The first menu ask for you to pick a product and each product has a price on it.

The second menu ask you to pick a state with each state having a decimal value on it.

The third is asking you to put the number of cases and each case is 12 items.

A key note to remember is that each part that a person is choosing is on a different instance!

Here is an example of what i am trying to do.

Menu 1: I picked case 1 that is Computer and it is worth 1000
Menu 2: I picked case 1 that is CT and it's tax is 7.5

Third choice: I picked case 1 and that has 12 items

I want the subtotal witch is: (1000 * 12)

Subtotal in this situation is: 120000

Next i need the total value which is based on what state they picked for the tax percent value picked from the state menu case: (12000 * 0.075 + 120000)

Total value is: 129000

I will post the code I have but based on the choices a person makes will determine the values and I need those values set in the cases to put in a math equation. The problem I am having is retrieving these numbers form the cases inside the menu options and they are on a different instance. So How can I do this in Java code?

Here is the code:

This is menu 1

Java Code:

import java.util.*; //scanners and more
class menu{
public void display_menu() {
System.out.println ("Please select your product"); //Gives user direction
System.out.println ( "1)

[Code] .....

View Replies View Related

Returning SQL Statement Instead Of Values From Database

Apr 9, 2014

I am reading value from database but my problem is am get sql statement values instead of values in database.
 
My code is ....

View Replies View Related

How To Print Found Or Not Found Only One Time

Oct 6, 2014

import java.util.Scanner;
public class Arraykey {
public static void main(String[] args) {
System.out.println("Enter array size: ");
Scanner input = new Scanner(System.in);
int size = input.nextInt();
int [] a = new int[size];
for(int i=0 ; i<size ; i++){

[Code] ....

View Replies View Related

Class Not Found In Jar

Feb 13, 2014

I have a jar file.and i imported its classes to my program..

let say i have a code

source code is at /home/t_bmf/Java/src
import firstjar.FirstJarPrint;
 public class TestJar {
public static void main(String[] args) {
//FirstJarPrint jar = new FirstJarPrint();
}
}

well i have successfully compiled it using command below:

javac -cp ".:/home/t_bmf/Java/lib/FirstJar.jar" -d /home/t_bmf/Java/bin TestJar.java

it means that i don't have any compilation error right?so all classes found properly.But whenever I run the program I always got this error:

java -cp /home/t_bmf/Java/lib/FirstJar/jar:. TestJar
Exception in thread "main" java.lang.NoClassDefFoundError: firstjar/FirstJarPrint
at TestJar.main(TestJar.java:6)
Caused by: java.lang.ClassNotFoundException: firstjar.FirstJarPrint
at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 47)
... 1 more

I think it has to be no error since i have compiled the program successfully right?if it really didn't find the class, then it must be a compilation error right?

is there something wrong with the way I execute the program?

note: i created the program in UNIX

View Replies View Related

File Not Found IO

Apr 10, 2015

I have an issue trying to read a file. Iam getting a file not found ex, but the file seems to be there.

This is my project

This the code that is loading the file.

Java Code: public GATEApplication(String appPath) {
try {
loadGATEApplication(appPath);

[Code].....

View Replies View Related

How To Switch Sides

Oct 21, 2014

I had to make a chart where it took miles 1-10 and convert it to kilometers and then on the other side it needs to show 25-65 (in 5's) kilometers to miles and I dont know how to switch the sides...

import java.util.Scanner;
public class MilesAndKilos {
public static void main(String[] args) {
int miles;
double kilometers=1.60934;
System.out.println(" Miles Kilometers Kilometers Miles");
for(miles=1;miles<10;miles++){
kilometers = miles * 1.60934;
System.out.printf(" %2d %8.3f |
", miles,kilometers);
}
}//end of main method
}

View Replies View Related

Manifest File Cannot Be Found

Nov 21, 2013

I am trying to create executable jar file and I have test.mf file located in the dir from where jar cmd(JavaTest) is executed and also in dir which contains class files (jTest).

C:Users
m2tDesktopJavaTest>jar cvfm JarTest4.jar test.mf jTest
java.io.FileNotFoundException: test.mf (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at java.io.FileInputStream.<init>(FileInputStream.java:79)
at sun.tools.jar.Main.run(Main.java:150)

[Code] .....

So how can Icreate manifest file and where shall I put it ?

View Replies View Related

Android Manifest Could Not Be Found

Apr 14, 2014

I am trying to run a project and i am getting different errors, I know the code is working because i have seen it running, but now i cant even get the app to load up. sometime I get a AndroidManifest cannot be found error and sometimes i get a error like

[2014-04-14 17:28:31 - DatabasePrototype5] Failed to install DatabasePrototype5.apk on device 'emulator-5554!
[2014-04-14 17:28:31 - DatabasePrototype5] (null)
[2014-04-14 17:28:32 - DatabasePrototype5] Launch canceled!

my AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.databaseprototype5"
android:versionCode="1"
android:versionName="1.0" >

[Code] ....

View Replies View Related







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