Post a New Question

Java

posted by on .

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.

Answer This Question

First Name:
School Subject:
Answer:

Related Questions

More Related Questions

Post a New Question