|
||||||
| Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hi everyone, I having a minor difficulty in sorting the menu.
Quote:
Code:
import java.io.*;
class TestService{
public static void main(String args []){
int selection;
Service array[]=new Service[6];
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("View The Report By \n");
System.out.println("1. Service");
System.out.println("2. Price");
System.out.println("3. Time");
System.out.println("4. Exit");
try{
do{
System.out.print("Enter selection :");
selection =Integer.parseInt(br.readLine());
if(selection ==1){
array[0]=new Service("Cut",8.00,15);
array[1]=new Service("Shampoo",4.00,10);
array[2]=new Service("Manicure",18.00,30);
array[3]=new Service("Style",48.00,55);
array[4]=new Service("Permanent",18.00,35);
array[5]=new Service("Trim",6.00,5);
}else if(selection ==2){
array[0]=new Service("Shampoo",4.00,10);
array[1]=new Service("Trim",6.00,5);
array[2]=new Service("Cut",8.00,15);
array[3]=new Service("Manicure",18.00,30);
array[4]=new Service("Permanent",18.00,35);
array[5]=new Service("Style",48.00,55);
}else if(selection ==3){
array[0]=new Service("Trim",6.00,5);
array[1]=new Service("Shampoo",4.00,10);
array[2]=new Service("Cut",8.00,15);
array[3]=new Service("Manicure",18.00,30);
array[4]=new Service("Permanent",18.00,35);
array[5]=new Service("Style",48.00,55);}
}while(!=4);
System.out.println();
System.out.println("Service"+"\t\t"+"Price<$>" +"\t" + "Time<Minutes>");
System.out.println("=======" + "\t\t" +"========" +"\t" + "=============");
for(int a=0;a<6;a++)
System.out.println(array[a].toString());
}
catch(NumberFormatException ex){
System.out.println("You can only enter number");
}
catch(IOException ex){
System.out.println("Input error");
}
}
}
|
| Sponsored Links |
|
|
|
|||
|
java.util.Arrays.sort() only can support 1 character, I having some difficulty to modify it. Here is a new program but it won't work after I change it back to array form. Please help me ....
![]() Code:
class Report{
String service;
double price;
int time;
public Report (){
}
public Report (String s,double d,int i){
service=s;
price=d;
time=i;
}
public void setService(String s){
service=s;
}
public String getService(){
return service;
}
public void setPrice(double d){
price=d;
}
public double getPrice(){
return price;
}
public void setTime(int i){
time=i;
}
public int getTime(){
return time;
}
public String toString(){
return getService() + "\t " + getPrice() + "\t\t\t" + getTime();
}
}
Code:
import java.io.*;
class TestReport{
public static void main (String args[]) throws IOException{
int x;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
Report salon1 = new Report("Cut ", 8.00, 15);
Report salon2 = new Report("Shampo ", 4.00, 10);
Report salon3 = new Report("Manicure ", 18.00, 30);
Report salon4 = new Report("Style ", 48.00, 55);
Report salon5 = new Report("Permanent ", 18.00, 35);
Report salon6 = new Report("Trim ", 6.00, 5);
do{System.out.println("View The Report By : \n");
System.out.println("1. Service\n2. Price\n3. Time\n4. Exit\n");
System.out.print("Enter Selection : ");
x=Integer.parseInt(br.readLine());
System.out.println("\n\n\n");
if(x==4){
System.out.println("Thanks for using this program!\n\n");
System.exit(-1);
}
System.out.println("Service \tPrice($)\tTime(minutes)");
System.out.println("==========\t========\t=============\n");
if(x==1){
System.out.println(salon1);
System.out.println(salon3);
System.out.println(salon5);
System.out.println(salon2);
System.out.println(salon4);
System.out.println(salon6);
}else if(x==2){
System.out.println(salon2);
System.out.println(salon6);
System.out.println(salon1);
System.out.println(salon3);
System.out.println(salon5);
System.out.println(salon4);
}else if(x==3){
System.out.println(salon6);
System.out.println(salon2);
System.out.println(salon1);
System.out.println(salon3);
System.out.println(salon5);
System.out.println(salon4);
}
else if(x==4){
System.out.println("Thanks for using this program!\n\n");
System.exit(-1);
}else{
System.out.println("\t<Data is not available because of wrong entry>\n\n");
}
System.out.println("\n\n\n\n");
}while(x!=4);
}
}
|
|
|||
|
Here is the result when I try to align, please help me see whether got any place to be improve or not?
Code:
import java.io.*;
class runsalon
{
public static void main(String args[])
{
salon type[]= new salon[6];
salon choose=new salon();
type[0]= new salon(leftAlign.left("Cut",10),8.00,15);
type[1]= new salon(leftAlign.left("Shampoo",10),4.00,10);
type[2]= new salon(leftAlign.left("Manicure",10),18.00,30);
type[3]= new salon(leftAlign.left("Style",10),48.00,55);
type[4]= new salon(leftAlign.left("Permanent",10),18.00,35);
type[5]= new salon(leftAlign.left("Trim",10),6.00,5);
do
{
try
{
System.out.println("View The Report By: ");
System.out.println("1. Service");
System.out.println("2. Price");
System.out.println("3. Time");
System.out.println("4. Exit");
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter selection: ");
choose.setSelect(Integer.parseInt(br.readLine()));
System.out.println("\n");
if(choose.getSelect()==1)
{
serviceType(type);
}
else if(choose.getSelect()==2)
{
priceType(type);
}
else if(choose.getSelect()==3)
{
minuteType(type);
}
}
catch(selectException ex)
{
System.out.println("Error" +ex.getMessage());
}
catch(IOException io)
{
System.out.println("Error: Invalid Selection");
}
System.out.println("\n");
}while(choose.getSelect()!=4);
}
public static void serviceType(salon type[])
{
int charCheck;
int charCompare;
int serviceIndex[]=new int[6];
int serviceChar[]=new int[6];
int temp=0;
for(int w=0;w<type.length;w++)
{
serviceChar[w]=type[w].getService().charAt(0);
serviceIndex[w]=w;
}
for(int x=0;x<type.length;x++)
{
for(int y=x+1;y<type.length;y++)
{
if(serviceChar[serviceIndex[x]]>serviceChar[serviceIndex[y]])
{
temp=serviceIndex[x];
serviceIndex[x]=serviceIndex[y];
serviceIndex[y]=temp;
}
else if(serviceChar[serviceIndex[x]]==serviceChar[serviceIndex[y]])
{
charCheck=type[serviceIndex[x]].getService().charAt(1);
charCompare=type[serviceIndex[y]].getService().charAt(1);
if(charCheck>charCompare)
{
temp=serviceIndex[x];
serviceIndex[x]=serviceIndex[y];
serviceIndex[y]=temp;
}
}
}
}
display(serviceIndex,type);
}
public static void priceType(salon type[])
{
int lowPriceIndex[]=new int[6];
int temp=0;
int charCheck;
int charCompare;
for(int w=0;w<type.length;w++)
{
lowPriceIndex[w]=w;
}
for(int x=0;x<lowPriceIndex.length;x++)
{
for(int y=x+1;y<type.length;y++)
{
if(type[lowPriceIndex[x]].getPrice()>type[lowPriceIndex[y]].getPrice())
{
temp=lowPriceIndex[x];
lowPriceIndex[x]=lowPriceIndex[y];
lowPriceIndex[y]=temp;
}
else if(type[lowPriceIndex[x]].getPrice()==type[lowPriceIndex[y]].getPrice())
{
charCheck=type[lowPriceIndex[x]].getService().charAt(0);
charCompare=type[lowPriceIndex[y]].getService().charAt(0);
if(charCheck>charCompare)
{
temp=lowPriceIndex[x];
lowPriceIndex[x]=lowPriceIndex[y];
lowPriceIndex[y]=temp;
}
}
}
}
display(lowPriceIndex,type);
}
public static void minuteType(salon type[])
{
int minuteIndex[]=new int[6];
int temp=0;
for(int w=0;w<type.length;w++)
{
minuteIndex[w]=w;
}
for(int x=0;x<minuteIndex.length;x++)
{
for(int y=x+1;y<type.length;y++)
{
if(type[minuteIndex[x]].getMinute()>type[minuteIndex[y]].getMinute())
{
temp=minuteIndex[x];
minuteIndex[x]=minuteIndex[y];
minuteIndex[y]=temp;
}
}
}
display(minuteIndex,type);
}
public static void display(int displayIndex[],salon type[])
{
System.out.println("Service\t Price($)\t Time(minutes)");
System.out.println("=======\t ========\t =============");
for(int z=0;z<displayIndex.length;z++)
{
System.out.println(type[displayIndex[z]].toString());
}
}
}
Code:
class salon
{
private String service;
private double price;
private int minute;
private int select;
public salon()
{
}
public salon(String s,double p,int m)
{
setService(s);
setPrice(p);
setMinute(m);
}
public void setService(String s)
{
service=s;
}
public String getService()
{
return service;
}
public void setPrice(double p)
{
price=p;
}
public double getPrice()
{
return price;
}
public void setMinute(int m)
{
minute=m;
}
public int getMinute()
{
return minute;
}
public String toString()
{
return getService() +"\t" +getPrice() +"\t\t" +getMinute();
}
public void setSelect(int c)throws selectException
{
if(c>4||c<1)
{
throw (new selectException("Invalid Selection"));
}
select=c;
}
public int getSelect()
{
return select;
}
}
Code:
class selectException extends Exception
{
public selectException(String x)
{
super(x);
}
}
Code:
class leftAlign
{
public static String left(String s, int size)
{
String temp=s;
for(int x=0;x<size-s.length();x++)
{
temp = temp +" ";
}
return temp;
}
}
|
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Php error handling | Jaan | PHP Tutorials | 2 | Today 07:32 AM |
| VB6.0:Tutorial, Error handling | TcM | VB Tutorials | 9 | 06-06-2008 01:31 PM |
| Download problem, internal Server Error | j3cubcapt | ionFiles | 1 | 07-02-2007 09:45 AM |
| Php - CGI Error | thesquirrel16 | General Programming | 1 | 05-19-2007 05:09 PM |
| can someone help me with my c librarys? | bobwrit | C and C++ | 4 | 04-27-2007 06:19 PM |
Goal: 100,000 Posts
Complete: 67%