Saturday, 15 June 2013

java - Do While Loop doesn't want to work for app -



java - Do While Loop doesn't want to work for app -

assignment 6 object array salon needs have menu loop user can utilize sorts till take '0' exit app.errors posted below code. know tried way without using 3 methods , got work need able utilize methods , while have advice or input can create work . thanks

import java.util.*; public class salonreport { public static void main(string[]args) { int x =0; service s1 = new service(); service s2 = new service(); service s3 = new service(); service s4 = new service(); service s5 = new service(); service s6 = new service(); s1.setservice("cut"); s1.setprice(5.00); s1.settime(15); s2.setservice("shampoo"); s2.setprice(5.00); s2.settime(10); s3.setservice("manicure"); s3.setprice(20.00); s3.settime(30); s4.setservice("style"); s4.setprice(60.00); s4.settime(55); s5.setservice("permanent"); s5.setprice(28.00); s5.settime(35); s6.setservice("trim"); s6.setprice(8.00); s6.settime(5); service[] services = {s1, s2, s3, s4, s5,s6}; //menu system.out.println("choose sort"); system.out.println("1: service"); system.out.println("2: price"); system.out.println("3: time"); system.out.println("0: exit"); scanner input = new scanner(system.in); do{ x = integer.parseint(input.next()); switch(x) { case 1: sortbyservice(services); break; case 2: sortbyprice(services); break; case 3: sortbytime(services); break; case 0: break; default: system.out.println("invalid entry"); }while(x!=0); } } public static void sortbytime(service[] array) { service temp; int highsubscript = array.length - 1; for(int = 0; < highsubscript; ++a) { for(int b = 0; b < highsubscript; ++b) { if(array[b].gettime() > array[b+1].gettime()) { temp = array[b]; array[b] = array[b + 1]; array[b + 1] = temp; } } } for(int = 0; < array.length; ++i) { system.out.println("service: "+array[i].getservice()+", "+"price: " +array[i].getprice()+", "+"time: "+ array[i].gettime()); } } public static void sortbyservice(service[] array) { service temp; int highsubscript = array.length - 1; for(int = 0; < highsubscript; ++a) { for(int b = 0; b < highsubscript; ++b) { if((array[b].getservice().comparetoignorecase(array[b+1].getservice())) >= 0) { temp = array[b]; array[b] = array[b + 1]; array[b + 1] = temp; } } } for(int = 0; < array.length; ++i) { system.out.println("service: "+array[i].getservice()+", "+"price: " +array[i].getprice()+", "+"time: "+ array[i].gettime()); } } public static void sortbyprice(service[] array) { service temp; int highsubscript = array.length - 1; for(int = 0; < highsubscript; ++a) { for(int b = 0; b < highsubscript; ++b) { if(array[b].getprice() > array[b+1].getprice()) { temp = array[b]; array[b] = array[b + 1]; array[b + 1] = temp; } } } for(int = 0; < array.length; ++i) { system.out.println("service: "+array[i].getservice()+", "+"price: "+array[i].getprice()+", "+"time: "+ array[i].gettime()); } } } salonreport.java:87: error: while expected } ^ salonreport.java:91: error: illegal start of look public static void sortbytime(service[] array) ^ salonreport.java:91: error: ')' expected public static void sortbytime(service[] array) ^ salonreport.java:91: error: ';' expected public static void sortbytime(service[] array) ^ salonreport.java:91: error: '.class' expected public static void sortbytime(service[] array) ^ salonreport.java:91: error: ';' expected public static void sortbytime(service[] array) ^ salonreport.java:116: error: illegal start of look public static void sortbyservice(service[] array) ^ salonreport.java:116: error: illegal start of look public static void sortbyservice(service[] array) ^ salonreport.java:116: error: ';' expected public static void sortbyservice(service[] array) ^ salonreport.java:116: error: '.class' expected public static void sortbyservice(service[] array) ^ salonreport.java:116: error: ';' expected public static void sortbyservice(service[] array) ^ salonreport.java:141: error: illegal start of look public static void sortbyprice(service[] array) ^ salonreport.java:141: error: illegal start of look public static void sortbyprice(service[] array) ^ salonreport.java:141: error: ';' expected public static void sortbyprice(service[] array) ^ salonreport.java:141: error: '.class' expected public static void sortbyprice(service[] array) ^ salonreport.java:141: error: ';' expected public static void sortbyprice(service[] array) ^ salonreport.java:166: error: reached end of file while parsing } ^ 17 errors ----jgrasp wedge2: exit code process 1. ----jgrasp: operation complete.

you missed }

it should

do{ x = integer.parseint(input.next()); switch(x) { case 1: sortbyservice(services); break; case 2: sortbyprice(services); break; case 3: sortbytime(services); break; case 0: break; default: system.out.println("invalid entry"); } }while(x!=0);

java arrays methods do-while

No comments:

Post a Comment