Java

posted by .

I am trying to write an algorithm for my JAVA class and am having some issues....if I were to post my program is there anyone on here that could help me figure out what I am doing wrong? Thanks

  • Java -

    Well perhaps I can help if its around the difficulty of AP Java A(Computer Science A).

  • Java -

    I will post the program I am trying to run just incase you can help. If you can't no worries. The issue I am having is when I run the program and enter in the number "100, 200, or 300" the box that is supposed to show up should be showing the televion display, description and price" and it does not do that.

    import java.io.*;
    import java.util.*;
    import javax.swing.JOptionPane;
    public class TVmodel3 {

    public static void main(String[] args) {
    //Decide model type
    String models; //Variable for model
    String outputStr; //Variable for output
    String salePrice; //Variable for sale price of home
    double price;

    models = JOptionPane.showInputDialog("Please enter the model number chosen,/nModel 100 comes with remote control, timer,\nand stereo sound and costs $1000, \nModel 200 comes with all features of model 100, \nand picture-in-picture, and costs $1200, \nModel 300 comes with all features of model 200 and /nHDTV, flat screen, 16 x 9 aspect ratio and costs $2400", JOptionPane.INFORMATION_MESSAGE);

    int model;
    model = 100;

    switch (model)
    {
    case 100:

    outputStr = "TV model";
    JOptionPane.showMessageDialog(null, outputStr,"You chose model 300 TV with these features:/nHDTV, flat screen, 16 x 9 aspect ratio, /npicture-in-picture, /nremote control, timer and stereo sound /nYour price will be $2400.00",JOptionPane.INFORMATION_MESSAGE);


    break;

    case 200:
    System.out.println ("You chose model 200 TV with these features:");
    System.out.println ("remote control, timer,stereo sound");
    System.out.println ("and picture-in-picture");
    System.out.println ("Your price will be $1200.00");
    break;

    case 300:
    System.out.println ("You chose model 300 TV with these features:");
    System.out.println ("HDTV, flat screen, 16 x 9 aspect ratio,");
    System.out.println ("picture-in-picture,");
    System.out.println ("remote control, timer and stereo sound \nYour price will be $2400.00");
    break;

    default:
    System.out.println("The Model entered is not available or invalid");

    }

    }
    }

  • Java -

    My language familiarity is mostly, c, c++, assembler, but here is something to check in your code.
    In the code, you are inputing to the string variable "models"; however, the switch statement is on the int "model". The variable "model" is hardcoded to a value of 100 in your code. I am thinking you intended to assign model the value converted from the string variable models.

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. Java help please

    I am trying to run the following program and am getting this error: java.util.InputMismatchException import java.io.*; import java.util.*; public class Pre2 { static Scanner console = new Scanner(System.in); public static void main(String[] …
  2. Java

    Can anybody help me figure how to post a Java file to as an attachment. I need to post this in my classroom forum but I have not clue to how. I am using the program called Netbeans. Thanks
  3. java

    Write a java application that finds the smallest of several integers. Prompt the user for the number of integers that will be input, then prompt the user for that number of integers. Evaluate the integers to determine the smallest …
  4. Java Programming

    I'm new to Java and I'm not sure how to write the source code for this problem I got in class... Write a java program using the while and if statement that will accept ten student grades and that will display the sum of the grades, …
  5. java programming

    write a java program using arrays function for hotel bill calculation?
  6. pseudo code algorithm

    Convert your algorithm from Question One into a complete Java application. Marks will be allocated based upon: ● Your Java code matching your pseudo code algorithm from Question One. ● Your Java code being syntactically …
  7. Java programming

    Okay so I am rewrite the program and it's still not coming right can anyone help me see what's going wrong here please I have to turn this in by tmw so here the program The following program is supposed to read two numbers from a file …
  8. computer science java

    write a program in java for a grocery (fruit shop calculate the prize of bananas @ $.89/kg declaring the the prices of all either as instances or class variables.declare the weight of the fruit as local variables
  9. computer, science, java, software

    Write a Java program to declare and store numbers from 1 to 10 in a single dimensional array and display the output in the following format. 1 2 3 4 5 6 7 8 9 10
  10. Programming

    Widget company runs a small factory that makes several types of nuts and bolts. They employ (a)1 (b)2 (c)3. Each factory worker can work a maximum of (a)40 hours normal working hours per week. All hours over 40 are paid as over-time …

More Similar Questions