Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: What is wrong with my code?

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post What is wrong with my code?

    PPA115D/TRO115D students are scheduled to write seven assessments this semester. The table below shows detailed information about the assessments.


    Assessment code Description Weight
    AS1 Assignment 1 10%
    AS2 Assignment 2 10%
    WT1 Web Test 1 5%
    WT2 Web Test 2 5%
    PR Project 10%
    FA Formative Assessment 20%
    SA Summative Assessment 40%


    For a student to pass PPA115D/TRO115D, she/he must attain a final mark of at least 50%. The final mark is calculated as follows:

    FinalMark = AS1 * 0.1 + AS2 * 0.1 + WT1 * 0.05 + WT2 * 0.05 + PR * 0.1 + FA * 0.2 + SA * 0.4

    Assume that we are now at the end of the semester and the final marks of students must be calculated. Say Thabiso who is a PPA115D student has the following record of marks:



    Assessment code Mark obtained
    AS1 90
    AS2 80
    WT1 40
    WT2 30
    PR 70
    FA 60
    SA 70

    Create an application that will display the marks of Thabiso as shown in the table above and thereafter determine and display his final mark.



    Here is my code:

     
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package finalmarkapp;
     
    /**
     *
     * @author SETH
     */
    public class FinalMarkApp {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // declare variables
            String code1="AS1",code2="AS2",code3="WT1",code4="WT2",code5="PR",code6="FA",code7="SA";
            int AS1 = 90,AS2 =80,WT1 = 40,WT2 = 30,PR = 70,FA = 60,SA =70;
            double FinalMark = AS1*0.1 + AS2*0.1 + WT1*0.05 + WT2 * 0.05 + PR *
                  0.1 + FA*0.2 + SA * 0.4;
     
           System.out.printf("%s%s\n", "Assessment code", "Mark obtained");
            System.out.printf("%-6s%-20d\n", code1,         AS1);
            System.out.printf("%-6s%-20d\n", code2,AS2);
            System.out.printf("%-6s%-20d\n", code3,WT1);
            System.out.printf("%-6s%-20d\n", code4,WT2);
            System.out.printf("%-6s%-20d\n", code5,PR);
            System.out.printf("%-6s%-20d\n", code6,FA);
            System.out.printf("%-6s%-20d"  , code7,SA);
            System.out.println("The final mark is: " + FinalMark);
        }
     
     
    }


    here's the output:

    Assessment codeMark obtained
    AS1   90                  
    AS2   80                  
    WT1   40                  
    WT2   30                  
    PR    70                  
    FA    60                  
    SA    70
    Last edited by Seth Lau.20; December 2nd, 2021 at 06:20 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: What is wrong with my code?

    Looks like a misplaced % before the \n

    Note: The OP has removed the misplaced % from the above code.
    Also the output has been added to that post.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2021
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What is wrong with my code?

    I want the marks displayed in the "mark obtained" column .and i can't separate the word code and mark in the output.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: What is wrong with my code?

    I want the marks displayed in the "mark obtained" column
    Increase the width of the first column to push the second and following columns to the right.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. What's wrong with this code
    By easypzz in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 30th, 2019, 03:22 PM
  2. What is wrong with my code?
    By aShibata in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 30th, 2018, 04:00 PM
  3. what's the wrong this code?
    By thilinasdn in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 17th, 2018, 05:13 AM
  4. Please what is wrong with my code
    By LordDavid in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 29th, 2012, 03:33 PM
  5. Please what is wrong with my code
    By LordDavid in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 28th, 2012, 09:08 PM