Question
Why isnt this compiling, even when I put the public static void main(String[] arg) it wont compile? full code: public class CollegeInfo { String college_name;
Why isnt this compiling, even when I put the public static void main(String[] arg) it wont compile?
full code:
public class CollegeInfo {
String college_name;
int sticker_price;
int net_price;
int discount;
//getter and setters of variables of class
public String getCollege_name() {
return college_name;
}
public void setCollege_name(String college_name) {
this.college_name = college_name;
}
public int getSticker_price() {
return sticker_price;
}
public void setSticker_price(int sticker_price) {
this.sticker_price = sticker_price;
}
public int getNet_price() {
return net_price;
}
public void setNet_price(int net_price) {
this.net_price = net_price;
}
//calculating discount provided by college
public void discount(){
discount=(int)((sticker_price-net_price)/sticker_price*100);
}
//returning the discount
public int getDiscount() {
return discount;
}
}
import java.util.Scanner;
public class MainClass {
//static members created to hold values which should not change with new object creation
static int avg_stick_price;//to hold average sticker price
static int avg_net_price;//to hold average net price
static int avg_discount;//to hold the discount
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter Number of colleges to be entered: ");
int n=sc.nextInt();//asking user to provide length of array
CollegeInfo[] college_array=new CollegeInfo[n];//creating college array
for(int i=0;i { college_array[i]=new CollegeInfo();//assigning array term class System.out.println("Enter Name of College: "); college_array[i].setCollege_name(sc.next());//using setters to enter values System.out.println("Enter Sticker Price: "); college_array[i].setSticker_price(sc.nextInt()); avg_stick_price=avg_stick_price+college_array[i].getSticker_price();//using getters to calculate total for calculating average System.out.println("Enter Net Price: "); college_array[i].setNet_price(sc.nextInt()); avg_net_price=avg_net_price+college_array[i].getNet_price(); college_array[i].discount(); avg_discount=avg_discount+college_array[i].getDiscount(); } System.out.format("%50s %16s %16s %16s ","College","Sticker Price","Net Price","% Discount Rate"); avg_stick_price=avg_stick_price; avg_net_price=avg_net_price; avg_discount=avg_discount; //printing the result for(int j=0;j { if(college_array[j].getDiscount()>=60) { //using string formatting System.out.format("%50s %16s %16s %16s ",college_array[j].getCollege_name()+"**","$"+college_array[j].getSticker_price(),"$"+college_array[j].getNet_price(),college_array[j].getDiscount()); }else if(college_array[j].getDiscount()>=50) { System.out.format("%50s %16s %16s %16s ",college_array[j].getCollege_name()+"*","$"+college_array[j].getSticker_price(),"$"+college_array[j].getNet_price(),college_array[j].getDiscount()); }else { System.out.format("%50s %16s %16s %16s ",college_array[j].getCollege_name(),"$"+college_array[j].getSticker_price(),"$"+college_array[j].getNet_price(),college_array[j].getDiscount()); } } System.out.format("%50s %16s %16s %16s","Average","$"+avg_stick_price,"$"+avg_net_price,avg_discount); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started