radhakrishna.p 29 Posting Whiz in Training

hai mtangpos16,

i have done some modifications to your code

you can not write a class inside a main method because main() method is starting point for creating objects but not starting point of the class creation/definition/declaration.

i think your code would be like as follows

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package googleproblem;

/**
 *
 * @author mtangpos
 */
public class GoogleProblem 
{

    public static void main(String[] args) {    

        Mobilephone mp = new Mobilephone(1, 1, 1, 1000, 1, "iphone", "mobile_department");

        //if you want to calculateInventory
        System.out.println("calculateInventory= " + mp.calculateInventory());

        //if you want to getDepartment();
        System.out.println("getDepartment= " + mp.getDepartment());

        //if you want to getInventoryStockValue();
        System.out.println("getInventoryStockValue= " + mp.getInventoryStockValue());

        //if you want to getInventoryValue();
        System.out.println("getInventoryValue =" + mp.getInventoryValue());

        //if you want to getItemNumber();
        System.out.println("getItemNumber= " + mp.getItemNumber());

        //if you want to getProductName();
        System.out.println("getProductName= " + mp.getProductName());

        //if you want to getSerialNumber();
        System.out.println(" getSerialNumber =" + mp.getSerialNumber());

        //if you want to getUnitPrice()
        System.out.println("getUnitPrice =" + mp.getUnitPrice());

        //if you want to getUnitsStock()
        System.out.println("getUnitsStock = " + mp.getUnitsStock());       

    }



class Mobilephone { //class name and attributes

            private int SerialNumber; //serial number of product
            private int ItemNumber; //item # of product
            private double UnitsStock; //# of units in stock
            private double UnitPrice; //Price per unit
            private double InventoryValue; //The dollar value of the inventory in stock
            private String Department; //The department the product belongs to
            private String ProductName; //product name
//constructor

            public Mobilephone(int item, int serial, double units, double price, double …
radhakrishna.p 29 Posting Whiz in Training

in addition to that please remove '%n' and replace it with '\n'

note : i dont know exactly if you are using %n for any special reason (leave it as it is if there is no special reason)

System.out.printf("%d. %s?%n", number, quizBank[number].question);

let me know the status

radhakrishna.p 29 Posting Whiz in Training

suggestions:

before storing a random number into the given array we have to consider 2 things

  1. whether array contains desired number of random numbers or not (to print the final array elements)

  2. whether the generated random number is existed in the array previously or not

if we achieve those 2 things then we will get the result as you expected

the following code does 2 things which i have explained above

import java.util.Random;

public class RandomizedArrayExample
{
    public static int[] myNumbers = null;    
    public static void main(String[] args)
    {
      try
      {
          myNumbers = new int[6];
          System.out.println(" my initial values ");
          for (int i = 0; i < myNumbers.length; i++) {
               System.out.println(myNumbers[i]);
          }

          Random r = new Random();
          int total_elements_cnt = 0;
          boolean loop_status = true;

          while(loop_status)
          {
              int next_num = r.nextInt(42)+1;          
              if(!isCompleted()){
                  if(!isDuplicate(next_num)){
                      myNumbers[total_elements_cnt] = next_num;
                      total_elements_cnt++;
                  }else{
                      continue;
                  }
              }else{
                  loop_status = false;
              }
          }
          System.out.println("-------- my final values -------------");
          for (int i = 0; i < myNumbers.length; i++) {
               System.out.println(myNumbers[i]);
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
  }

  public static boolean isCompleted(){
      boolean status = true;
      for (int i = 0; i < myNumbers.length; i++){
          if(myNumbers[i]==0){
              status = false;
              break;
          }
      }
      return  status;
  }

  public static boolean isDuplicate(int num){
      boolean status = false;
      for (int i = 0; i < myNumbers.length; i++){
          if(myNumbers[i]== num){
              status = true;
              break;
          }
      }
      return  status;
  }
}

check it once and let me know the status

happy coding

radhakrishna.p 29 Posting Whiz in Training

we can achieve this by using AttributedString class which is available in java.text.*; package

the following url's may help you for this

http://www.java2s.com/Code/JavaAPI/java.text/TextAttributeSUPERSCRIPT.htm

http://www.daniweb.com/software-development/java/threads/186751/printing-powers-in-java

please check it once