Results 1 to 20 of 20
Like Tree1Likes
  • 1 Post By Norm

Thread: Project help

  1. #1
    ghjk is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Project help

    This is for school..(:

    Well here is the problem.

    What you see is the problem..you dont have to read it all. But my main question is down at the bottom where I have to ask the model, mpg, and production. I need it to where I can enter the first one...and have it not skip the rest of it. after I enter the first model..it skips the other two..Why???

    Also

    I need to extract what they say and post it down towards the bottom...i think i have an idea on that..but not exactly sure..but anyways help please (:

    Java Code:
    parameters (a ... d) which are adopted for each model year as shown in Table 1.
    (1) T = 1/(1/a + (1/b - 1/a)*e(x-c)/d/(1 + e(x-c)/d))
    where:
    T - fuel economy target, mpg
    a - maximum fuel economy target, mpg
    b - minimum fuel economy target, mpg
    c - footprint value at which the fuel economy target is midway between a and b, ft
    2
    d - rate at which the value of targets decline from the largest to smallest values, ft
    2
    e = 2.718
    x - footprint of the vehicle model, ft
    2
    Table 1
    Parameter Values for Determination of CAFE Targets
    Parameter
    Year
    2008 2009 2010 2011
    a) |28.56 |30.07 |29.96 |30.42
    b) |19.99 |20.87 |21.20 |21.79
    c) |49.30 |48.00 |48.49 |47.74
    d) |5.58 |5.81 |5.50 |4.65
    
              For a fleet of three models the following equation would be used:
    (2) Fleet Fuel Economy =             Total Production
                         -------------------------------------------
                           NVehicle1    NVehicle2     NVehicle3
                           ---------  +  ---------  +  ---------
                             MPG1          MPG2          MPG3
    
    Example
    If these vehicles had the fuel economies and production figures shown in Table 2, then the Fleet Fuel 
    Economy would be calculated as
    Fleet Fuel Economy =             350,000
                         --------------------------------
                           130,000     120,000   100,000
                           -------  +  ------- + -------
                             22          20         16
    Fleet Fuel Economy =  19.27.
    
    
    
    Functional Requirements
    
    1. The program must display a welcome message at the beginning of program execution as shown 
    below:
    Welcome to the 2011 CAFE Compliance Analyzer for CS Motors.
    2. The program must prompt for and read the footprint used to compute the target fuel economy as 
    shown below (sample user input is shown in light green):
    Enter vehicle footprint: 43.25
    3. The program must prompt for and read the model name, production amount and mpg rating for 
    exactly three models manufactured by CS Motors as shown below (sample user input is shown in 
    light green):
    Enter model name, production amount and mpg rating for model 1: Bit 5000 21.18
    Enter model name, production amount and mpg rating for model 2: Byte 6900 20.76
    Enter model name, production amount and mpg rating for model 3: Word 1922 25.83
    4. The program must compute the target fuel economy using equation (1).
    5. The program must compute the fleet fuel economy using equation (2).
    6. The program must generate the following report. Values supplied by variables are shown in angle 
    brackets:
    2011 CAFE Compliance Analysis Report for CS Motors
    ---------------------------------------
    Vehicle footprint: <footprint> sq. ft.
    Target fuel economy: <targetFuelEconomy> mpg.
    Model Production MPG
    ----- ---------- ---
    <v1Name> <v1Production> <v1Mpg>
    <v2Name> <v2Production> <v2Mpg>
    <v3Name> <v3Production> <v3Mpg>
    Fleet fuel economy: <fleetFuelEconomy> mpg.
    
    Sample Runs
    
    Two sample runs of the entire program are shown below. Inputs, which are shown in green, are 
    representative and may not be the same as used to test your program. You should, however, test your 
    program with the values given to gain some confidence that your program satisfies the functional 
    requirements.
    Sample Run #1
    Welcome to the 2011 CAFE Compliance Analyzer for CS Motors.
    Enter vehicle footprint: 43.25
    Enter model name, production amount and mpg rating for model 1: Bit 5000 21.18
    Enter model name, production amount and mpg rating for model 2: Byte 6900 20.76
    Enter model name, production amount and mpg rating for model 3: Word 1922 25.83
    2011 CAFE Compliance Analysis Report for CS Motors
    --------------------------------------------------
    Technical Requirements1. The Java class containing the program must be named, CafeComplianceAnalyzer.
    2. The program must define the following named constants:
    Identifier Value Description
    _________________________________________________
    |MAX_FUEL_ECONOMY 30.42 Parameter a from Equation 1|
    |MIN_FUEL_ECONOMY 21.79 Parameter b from Equation 1 |
    |MIDWAY_FOOTPRINT 47.74 Parameter c from Equation 1 |
    |RATE 4.65 Parameter d from Equation 1                        |
    --------------------------------------------------------
    3. The program must use the exp method of the Math class for parameter e in Equation 1.
    
    4. The program must declare variables with the names shown in Functional Requirement #6 to 
    hold the programís input data and calculated results. If you need other variables to hold 
    intermediate calculations, you may choose whatever names you feel are appropriate.
    
    5. The program must use only tab characters to effect spacing within the table containing model 
    production and fuel economy values.
    Documentation Requirements
    ---------------------------------------------------------------------------------------------
    1. You must have a comment preceding each essential step in your code. Especially important to 
    do so for statements that perform the required inputs, computations, and outputs.
    
    2. You must have a comment block at preceding the Java class header that has the following 
    content:
    /*
    * <your name>
    * CS160 Spring 2012
    * Project 1: CAFE Compliance Analyzer
    *
    * Description. <Summarize the purpose of the program here.>
    *
    */
    Design
    The program will consist of a single user-defined class named CafeComplianceAnalyzer as described in 
    the table below. 
    CafeComplianceAnalyzer
    Name Descriptionmain()  1. Declare all named constants
    2. Declare all variables
    3. Declare and instantiate a Scanner object to read data 
    from the keyboard
    4. Display the welcome message
    5. Solicit and read value for vehicle footprint
    6. Calculate target fuel economy
    7. Solicit and read data for the first vehicle model
    8. Solicit and read data for the second vehicle model
    9. Solicit and read data for the third vehicle model
    10. Calculate fleet fuel economy
    11. Generate CAFE Compliance Analysis report
    Submission
    Export your Eclipse project as an Archive file and upload it to Blackboard.
    This is what I have so far...and It messes up on the middle part, where they have to enter in the three models, and I def need help. I have it down to where you have to ask for the models...and it skips over it..I need help please (:

    Java Code:
    import java.util.Scanner;
    
    
    /*
    * 
    * Spring 2012
    * Project 1: CAFE Compliance Analyzer
    *
    * Description. The purpose of this program is to use the formula to calculate and generate
    * the MPG, the footprint, Target fuel economy, use both equations to solve for it, then 
    * display them at the bottom of the window
    *
    */
    public class CafeComplianceAnalyze {
        public static void main(String[] args) {
        
            Scanner KB = new Scanner(System.in);
            
            double VehicleFootPrint;
            final double MAX_FUEL_ECONOMY =  30.4;
            final double MIN_FUEL_ECONOMY =  21.7;
            final double MIDWAY_FOOTPRINT =  47.7;
            final double RATE = 4.65;
            final double e = 2.78;
            double T;
            String Model1;
            String Model2;
            String Model3;
            
            //Display a welcome message
            System.out.println("Welcome to the 2011 CAFE Compliance Analyzer for CS Motors");
            
            //Ask for the Vehicle Footprint
            System.out.print("Enter vehicle footprint: ");
            VehicleFootPrint = KB.nextDouble();
            
            // prompt for and read the model name, production amount and mpg rating for 
            //exactly three model
            System.out.print("Enter model name, production amount and mpg rating for model 1: ");
            Model1 = KB.next();
            System.out.print("Enter model name, production amount and mpg rating for model 2: ");
            Model2 = KB.next();
            System.out.print("Enter model name, production amount and mpg rating for model 3: ");
            Model3 = KB.next();
            
            //Enter the numbers into the First Equation
             T = 1/(1/MAX_FUEL_ECONOMY + (1/MIN_FUEL_ECONOMY - 1/MAX_FUEL_ECONOMY)*e(Math.exp(VehicleFootPrint-MIDWAY_FOOTPRINT)/RATE)/(1 + e(Math.exp(VehicleFootPrint-MIDWAY_FOOTPRINT)/RATE)));
            
            //Enter the numbers into second equation
             
             
             
            //Present the overall data on the screen
             System.out.println("2011 CAFE Compliance Analysis Report for CS Motor");
             System.out.println("-------------------------------------------------");
             System.out.println("Vehicle footprint: " + VehicleFootPrint + "sq ft.");
             System.out.println("Target fuel economy: " + T + "mpg.\n");
             System.out.println("Model\t" + "Production\t" + "Mpg");
             System.out.println("-----\t" + "----------\t" + "---");
    
    
        }
    
    
        private static int e(double d) {
            // TODO Auto-generated method stub
            return 0;
        }
    
    
    }

    Anyone help me out? lol :P

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Project help

    after I enter the first model..it skips the other two..Why???
    Try printing out what is read in as it is read so you know what the program is getting for data. Print out Model1 and 2 and 3.

    Can you copy and paste the contents of the command prompt window when you execute the program so I can see what is happening?

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  3. #3
    ghjk is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Project help

    Well, I got past that part, but now I need to write a formula, with those numbers included that they enter..not the "Byte Bite" or anything they enter...just the numbers. Which I def forget how to do. but I will do!

    BTW what i figured out...I needed to add another line..so I needed to add KB.nextLine(); underneath again. so it writes a new line for both. but here is my code now

    Java Code:
    import java.util.Scanner;
    
    /*
    * 
    * CS160 Spring 2012
    * Project 1: CAFE Compliance Analyzer
    *
    * Description. The purpose of this program is to use the formula to calculate and generate
    * the MPG, the footprint, Target fuel economy, use both equations to solve for it, then 
    * display them at the bottom of the window
    *
    */
    public class CafeComplianceAnalyze {
    	public static void main(String[] args) {
    	
    		Scanner KB = new Scanner(System.in);
    		double VehicleFootPrint;
    		final double MAX_FUEL_ECONOMY =  30.4;
    		final double MIN_FUEL_ECONOMY =  21.7;
    		final double MIDWAY_FOOTPRINT =  47.7;
    		final double RATE = 4.65;
    		final double e = 2.78;
    		double T;
    		double Fleet;
    		String Model1 = "";
    		String Model2 = "";
    		String Model3 = "";
    		
    		
    		
    		//Display a welcome message
    		System.out.println("Welcome to the 2011 CAFE Compliance Analyzer for CS Motors");
    		
    		//Ask for the Vehicle Footprint
    		System.out.print("Enter vehicle footprint: ");
    		VehicleFootPrint = KB.nextDouble();
    		
    		// prompt for and read the model name, production amount and mpg rating for 
    		//exactly three model
    		System.out.print("Enter model name, production amount and mpg rating for model 1:");
    		Model1 = KB.next();
    		KB.nextLine();
    		System.out.print("Enter model name, production amount and mpg rating for model 2: ");
    		Model2 = KB.next();
    		KB.nextLine();
    		System.out.print("Enter model name, production amount and mpg rating for model 3: ");
    		Model3 = KB.next();
    		KB.nextLine();
    		//Enter the numbers into the First Equation
    		 T = 1/(1/MAX_FUEL_ECONOMY + (1/MIN_FUEL_ECONOMY - 1/MAX_FUEL_ECONOMY)*e(Math.exp(VehicleFootPrint-MIDWAY_FOOTPRINT)/RATE)/(1 + e(Math.exp(VehicleFootPrint-MIDWAY_FOOTPRINT)/RATE)));
    		
    		//Enter the numbers into second equation
    
    		 //HERE is the equation
    //Fleet Fuel Economy =             Total Production(T)
    //                     -------------------------------------------
    //                          ( Model First ##)    (Model2 First #)     (Model3 First#)
    //                                 ---------  +       ---------       +    ---------
    //                           (Model1 2nd ##)   (Model2 2nd #)       (Model3 2nd #)
    
    
    		 
    		//Present the overall data on the screen
    		 
    		 System.out.println("2011 CAFE Compliance Analysis Report for CS Motor");
    		 System.out.println("-------------------------------------------------");
    		 System.out.println("Vehicle footprint: " + VehicleFootPrint + "sq ft.");
    		 System.out.println("Target fuel economy: " + T + "mpg.\n");
    		 System.out.println("Model\t" + "Production\t" + "Mpg");
    		 System.out.println("-----\t" + "----------\t" + "---");
    		 System.out.println(Model1);
    		 System.out.println(Model2);
    		 System.out.println(Model3);
    //I need to enter them in like... Where you see (Model1); it should say.."Word they type"         "First number they type"       "Second number" above
    
    	}
    
    	private static int e(double d) {
    		// TODO Auto-generated method stub
    		return 0;
    	}
    
    }
    Last edited by ghjk; 02-08-2012 at 02:33 AM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Project help

    Did you have another question?

  5. #5
    ghjk is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Project help

    Yeah...how do I get the numbers from what they enter in for model1, model2 and model3.

    At the end, It should look like this.

    I need those numbers after like "Fetcher" "Decoder" and "EXE", to use in a equation. Thank you!

    Java Code:
    Welcome to the 2011 CAFE Analysis Application for CS Motors.
    Enter vehicle footprint: 42.65
    Enter model name, production amount and mpg rating for model 1: Fetcher 120000 32.43
    Enter model name, production amount and mpg rating for model 2: Decoder 150000 27.88
    Enter model name, production amount and mpg rating for model 3: Exe 260000 29.54
    2011 CAFE Compliance Analysis Report for CS Motors
    --------------------------------------------------
    Vehicle footprint: 42.65 sq. ft.
    Target fuel economy: 27.671908321523173 mpg.
    Model Production MPG
    ----- ---------- ---
    Fetcher 120000 32.43
    Decoder 150000 27.88
    Exe 260000 29.54
    Fleet fuel economy: 29.638571659994017 mpg.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Project help

    .how do I get the numbers from what they enter in for model1, model2 and model3.
    The values that were entered are in those variables: model1, model2 and model3.

    Did you do what I suggested here:
    Try printing out what is read in as it is read so you know what the program is getting for data. Print out Model1 and 2 and 3.

  7. #7
    ghjk is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Project help

    So, if i wanted to extract those numbers...how would you say I would go about that? If you could help

    and I didnt really get what you meant, because they are numbers being entered. not set ones, so They print out correctly...I just need to extract the numbers only to put them in a equation.

    Also I have to list those numbers and the word they said at the bottom of the screen, as you can see above in one of the older post.

    If I just have (Model1), it only says the first word until I hit space..and it doesnt say anything else after that...which I need it to say the numbers aswell..=\

    Java Code:
     System.out.println("2011 CAFE Compliance Analysis Report for CS Motor");
             System.out.println("-------------------------------------------------");
             System.out.println("Vehicle footprint: " + VehicleFootPrint + "sq ft.");
             System.out.println("Target fuel economy: " + T + "mpg.\n");
             System.out.println("Model\t" + "Production\t" + "Mpg");
             System.out.println("-----\t" + "----------\t" + "---");
             System.out.println(Model1);
             System.out.println(Model2);
             System.out.println(Model3);
    //I need to enter them in like... Where you see (Model1); it should say.."Word they type"         "First number they type"       "Second number" above
    Last edited by ghjk; 02-08-2012 at 03:01 AM.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Project help

    Please explain what you mean by "extract those numbers".
    The user entered them and they were saved in the variables.

  9. #9
    ghjk is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Project help

    So what i mean is...like

    I need them for the equation. but since the first thing they type is a word..it doesnt work..i only need the integers.

    Like for example...my formula is

    Java Code:
    Fleet =         T/      1st#Model1    1st#Model2     1st#Model3
                                ---------   +    ---------    +  ---------
                               2nd#Model1    2nd#Model2     2nd#Model3
    so for 1st#Model1=First number they entered on model 1 and 2nd#Model1= second number entered in the first Model1

    And so on like that...you get what Im saying?

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Project help

    When you get the input from the user, you need to ask that the correct type of data be entered. If you need a number then the user should enter a number. If you need a String, then the user needs to enter a String.
    The Scanner class has many methods for getting different types of input from the user. You need to look at the API doc for the Scanner class and chose the method to use for the type of data that you want the user to enter.

  11. #11
    ghjk is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Project help

    Well my teacher assigned it so they have to enter a word, and two numbers following...so its all being stored in a string. and If i just want a certain position on the string...such as when the first number should start to where it ends when there is a space..is there something like that?

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Project help

    Can you print out what is being read into the program?
    As I said, the Scanner class has methods for reading different types of data.
    Is all the data in one String with the different parts separated by spaces?

  13. #13
    ghjk is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Project help

    Java Code:
    Welcome to the 2011 CAFE Compliance Analyzer for CS Motors
    Enter vehicle footprint: 65.76
    Enter model name, production amount and mpg rating for model 1: bro 5600 67
    Enter model name, production amount and mpg rating for model 2: bute 333 56
    Enter model name, production amount and mpg rating for model 3: bite 5678 23
    2011 CAFE Compliance Analysis Report for CS Motor
    -------------------------------------------------
    Vehicle footprint: 65.76sq ft.
    Target fuel economy: 30.400000000000002mpg.
    
    Model	Production	Mpg
    -----	----------	---
    
    
    
    Fleet fuel economy: mpg.
    This is my code after I run it. The green part of course is the stuff I entered in. I have to have a word like you see where the Model1, Model2, and Model3 are at the beginning. and the numbers after, are the numbers I need for my equation. the first number represents the Production, and the second number represents the MPG. So for each one I need to get those numbers to enter in my equation.

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Project help

    I don't see where you print out the values of model1 and model2 and model3.
    You need to print it this way so it is very easy to see what the variable contains:
    System.out.println("model1=" + model1 + "<");
    And the same for 2 and 3

    I can not see where the numbers are you are talking about from what you posted in post#13

  15. #15
    ghjk is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Project help

    Well that is the thing...
    System.out.println("model1=" + model1 + "<"); Using that only says the first word...so if we were going off the picture here...it would only display

    Model1=Bro<

    When I want just the "5600" and the "67" for model 1
    "333" and "56" for model 2
    "5678" and "23" for model 3
    So I want whatever the user enters for the numbers..to be in my equation below.

    To enter in my equation for
    Fleet = T/((5600/67)+(333/56)+(5678/23)) <<<That is what I want for my code...so I need those numbers..I cant use

    Fleet = T/((Model1)+(Model2)+(Model3))<<<<That doesnt work..cuz if you look at my code..it has a char first. But I need my Char their cuz its part of the rules he wants.

    Java Code:
    Welcome to the 2011 CAFE Compliance Analyzer for CS Motors
    Enter vehicle footprint: 65.76
    Enter model name, production amount and mpg rating for model 1: bro 5600 67
    Enter model name, production amount and mpg rating for model 2: bute 333 56
    Enter model name, production amount and mpg rating for model 3: bite 5678 23
    2011 CAFE Compliance Analysis Report for CS Motor
    -------------------------------------------------
    Vehicle footprint: 65.76sq ft.
    Target fuel economy: 30.400000000000002mpg.
     
    Model   Production  Mpg
    -----   ----------  ---
     
     
     
    Fleet fuel economy: mpg.

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Project help

    You didn't print out the values for model2 and model3? ????

    You need to print out all three variables so you can see where the user's input is going.

    Also you need to read the API doc for the Scanner class to see other methods that may be useful to you.

    That's it for tonight. Back tomorrow.

  17. #17
    ghjk is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Project help

    Alright. Thank you for helping me out. Im still not sure what you mean by I didnt print out model2 and model3.....

    But thanks for the help!

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Project help

    not sure what you mean by I didnt print out model2 and model3.....
    Model1=Bro<
    Here you printed out the value of model1
    There should be two more lines of printed output, one for model2 and one for model3:
    Model2=????<
    Model3=????<

    You need to print them out so you see where the user's input is going.

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default Re: Project help

    You are hitting "Fun With Scanner" mode I think.
    Here's the API for next().
    "Finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern."

    Now, the default delimiter is whitespace (ie any blank, tab, return, that sort of thing), so your calls to next() are only returning the first bit of your entered String, as you've noticed.
    You then call nextLine(), which returns everything else up to the new line character (ie your <return>)...and you throw that away.

    So...either use nextLine and put that all into the MOdel1/2/3 variables and then figure out how to get at the numbers, or read all three bits into different variables (nextInt() might prove useful here).

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Project help

    The OP needs to write a small simple program that uses the Scanner class's methods and try many of them out to see what they do.
    Read in a value using one of the methods and print out the results to see what how the method works.
    Also try using the methods whose names begin with has...() to see how to use them.
    Tolls likes this.

Similar Threads

  1. Creating a project in eclipse from existing project
    By Suraiya in forum New To Java
    Replies: 1
    Last Post: 10-08-2011, 09:14 AM
  2. How to convert from Ant project to maven project?
    By jiapei100 in forum New To Java
    Replies: 0
    Last Post: 06-08-2011, 10:01 AM
  3. Adding a project to an existing project
    By Seijuro in forum NetBeans
    Replies: 4
    Last Post: 08-08-2010, 10:15 AM
  4. open existing project project ..
    By itaipee in forum Eclipse
    Replies: 1
    Last Post: 12-28-2008, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •