Adult Content Warning

This community may contain adult content that is not suitable for minors. By closing this dialog box or continuing to navigate this site, you certify that you are 18 years of age and consent to view adult content.

Programming -- shell / java / c# / python / ada / lisp

Discussion in 'Technical Board' started by Nettdata, Dec 1, 2009.

  1. LatinGroove

    LatinGroove
    Expand Collapse
    Emotionally Jaded

    Reputation:
    9
    Joined:
    Jun 28, 2010
    Messages:
    584
    Location:
    Texas
    I'm working on some java homework and I honestly have no idea what the fuck I'm doing. It's been forever since I worked on any programming so I might as well be working on particle physics.

    The whole idea is working with setters and getters. Any ideas on how to get this fucking thing to compile? Here is essentially what should be output when compiled:

    Name: Bob
    Age: 15
    Type of Student: High School

    Name: ted Age: 35
    Type of Student: College

    Here is what I have for the StudentClient.java file which I am NOT allowed to modify in any way whatsoever.

    Code:
    public class StudentClient{
      public static void main( String [] args ){
        Student student1 = new Student("Bob", 15);
        Student student2 = new Student("Jan", 13);
        System.out.println("Name: " + student1.getName());
        System.out.println("Age: " + student1.getAge());
        System.out.println("Type of Student: " + student1.determineTypeOfStudent());
    
        System.out.println("\n" + student2.fullString());
        System.out.println("Type of Student: " + student2.determineTypeOfStudent());
    
        student1.setName("Ted");
        student1.setAge(35);
    
        System.out.println("\n" + student1.fullString());
        System.out.println("Type of Student: " + student1.determineTypeOfStudent());
      } 
    }  
    
    
    
    Here is the Student.java file which I can modify in anyway I see fit. I have blocked off a section of code just so I can get attempt to get the thing to run. Here is the error I am getting "Method determineTypeOfStudent in class Student cannot be applied to given types

    Reason: actual and formalt argument lists differ in length."

    Code:
    public class Student{
        //define variables
        
        private String name;
        private double age;
        
        //Student constructor
        public Student(String newName, double newAge) {
            setName(newName);
            setAge(newAge);
        }
        
        //Mutator to set student type
        public void setName(String newName) {
            name = newName;
        }
        
        //Accessor to get the student type
        public String getName() {
            return name;
        }
        
        //Mutator to check validity of data
        
        public void setAge(double newAge) {
            if (newAge >= 0) {
                age = newAge;
            }else {
                System.out.println("Age cannot be a negative.");
            }
        }
    
        //Accessor to get the student age
        
        public double getAge() {
            return age;
        }
        
        //Method to return student type, name, and age
        public String fullString() {
            return  ("\nName: " + name + "\nAge: " + age);
        }
    
        //method determines type of student
        public String determineTypeOfStudent(Student TypeOfStudent) {
            if (TypeOfStudent.age >= 0 & age <= 4){
                return "Preschool";
                //System.out.println("Preschool");
            /*}else if (newAge = 5){
                System.out.println("Kindergarten");
            }else if (newAge >= 6 & newAge <= 10) {
                System.out.println("Elementary School");
            }else if (newAge >= 11 & newAge <= 13) {
                System.out.println("Middle School");
            }else if (newAge >= 14 & newAge <= 17) {
                System.out.println("High School");
            }else if (newAge >= 18) {
                System.out.println("College");
            }    */
        }   else{    
            return null;
        
    } 
    }
    }
    
    
    
    
     
  2. LatinGroove

    LatinGroove
    Expand Collapse
    Emotionally Jaded

    Reputation:
    9
    Joined:
    Jun 28, 2010
    Messages:
    584
    Location:
    Texas
    Does this make sense to everyone else? Ignore the fact it actually compiles.

    Code:
    public class Student{
        //define variables
        
        private String name;
        private double age;
        
        //Student constructor
        public Student(String newName, double newAge) {
            setName(newName);
            setAge(newAge);
        }
        
        //Mutator to set student name
        public void setName(String newName) {
            name = newName;
        }
        
        //Accessor to get the student type
        public String getName() {
            return name;
        }
        
        //Mutator to check validity of data
        
        public void setAge(double newAge) {
            if (newAge >= 0) {
                age = newAge;
            }else {
                System.out.println("Age cannot be a negative.");
            }
        }
    
        //Accessor to get the student age
        
        public double getAge() {
            return age;
        }
        
        //Method to return student name and age
        public String fullString() {
            return  ("\nName: " + name + "\nAge: " + age);
        }
    
        //method determines type of student
        public String determineTypeOfStudent() {
            if (age > 0 & age < 4){
                return "Preschool";
            }else {if (age >= 5 & age <= 5){
                return "Kindergarten";
            }else {if (age >= 6 & age <= 10) {
                return "Elementary School";
            }else {if (age >= 11 & age <= 13) {
                return "Middle School";
            }else {if (age >= 14 & age <= 17) {
                return "High School";
            }else {if (age >= 18) {
                return "College";
            }else {
                return null;
            }
            }
            }
            }
            }
            }
        }
    }
     
  3. GremlinD

    GremlinD
    Expand Collapse
    Village Idiot

    Reputation:
    10
    Joined:
    Nov 5, 2009
    Messages:
    11
    First, your definition for the determineTypeOfStudent method requires an input parameter. When your code calls it, you aren't passing it that parameter. So it should be:

    Code:
     student1.determineTypeOfStudent(student1)
    Secondly, in that method, your test for "Kindergarten" won't compile. In an IF statement, the test should use == to test for equality.

    I took your code and was able to get it to work with those changes.
     
  4. AFHokie

    AFHokie
    Expand Collapse
    Emotionally Jaded

    Reputation:
    282
    Joined:
    Apr 13, 2010
    Messages:
    1,436
    Location:
    Manassas, VA
    Basically, I'm at the starting line, but I have no idea what direction I'm supposed to proceed. I'd like to learn SQL. However, other than knowing SQL is database management, I'm at a loss where to start to learn it. Based on what's posted in the thread, I do have a couple ideas for projects but I'm not sure where to go for basic learning. I found Microsoft's offering: https://www.microsoft.com/learning/en-us/sql-training.aspx However, I tend to learn and retain better with a real book in my hands. I found O'Reilly's Learning SQL http://shop.oreilly.com/product/9780596007270.do

    Are their other books or websites anyone would suggest I look up?
     
  5. Nettdata

    Nettdata
    Expand Collapse
    Mr. Toast

    Reputation:
    2,863
    Joined:
    Feb 14, 2006
    Messages:
    25,737
  6. Nettdata

    Nettdata
    Expand Collapse
    Mr. Toast

    Reputation:
    2,863
    Joined:
    Feb 14, 2006
    Messages:
    25,737
    Yes and no.

    Data model design is pretty key, but is hard to learn from books... experience and exposure to other projects is what really helps that.

    If you're just doing some basic programming of a simple system, INSERT/UPDATE/DELETE, cursors, EXPLAIN PLAN, and the various joins will get you through.

    As you get more advanced, and have to incorporate things like performance, security, and data management, you learn about stored procedures, views, materialized view, partitioning, locking strategies, triggers, replication, memory management, etc.

    Then, if you're really fucking insane, you get into data warehousing.
     
  7. redbullgreygoose

    redbullgreygoose
    Expand Collapse
    Disturbed

    Reputation:
    2
    Joined:
    Oct 19, 2009
    Messages:
    498
    Can Anyone recommend a PostGreSQL hosting service? Are they all the same and is there any noticeable difference between any of them?
     
  8. Nettdata

    Nettdata
    Expand Collapse
    Mr. Toast

    Reputation:
    2,863
    Joined:
    Feb 14, 2006
    Messages:
    25,737
    I’d just use AWS RDS Postgres. Pretty cheap, well managed (backups, encryption, firewalling, etc).
     
  9. redbullgreygoose

    redbullgreygoose
    Expand Collapse
    Disturbed

    Reputation:
    2
    Joined:
    Oct 19, 2009
    Messages:
    498
    Got it. I'll sign up for an account now. Thank you.
     
  10. Nettdata

    Nettdata
    Expand Collapse
    Mr. Toast

    Reputation:
    2,863
    Joined:
    Feb 14, 2006
    Messages:
    25,737
    I don't know what your requirements are, but I use AWS RDS in quite a few Production environments. I run this site (with mysql and postgres) for about $10 a month with a hosted VM at Linode, where I have a basic Ubuntu image that I then install/run whatever I want. Depends on how handy you are with sysadmin stuff, and what you're looking to do with it.

    For least hassle, yeah, AWS RDS is hard to beat... especially with their backup/recovery/admin stuff being as automatic and simple as it is. It can also scale pretty fucking big with a push of a button.
     
  11. redbullgreygoose

    redbullgreygoose
    Expand Collapse
    Disturbed

    Reputation:
    2
    Joined:
    Oct 19, 2009
    Messages:
    498
    I'll be putting it into production but I doubt I will have to scale very large at all. It's simply for a python portfolio / resume for an app I am building with Django 2.X. I don't expect many to use it. In my case, the less hassle / easier Amazon makes it, the better.
     
  12. Nettdata

    Nettdata
    Expand Collapse
    Mr. Toast

    Reputation:
    2,863
    Joined:
    Feb 14, 2006
    Messages:
    25,737
    I have 3 clients that we rolled out RDS PG with, some at pretty serious scale, and it's going rock solid... including read-replicas. It's a pretty impressive offering from AWS. (We also use a ton of Dynamo and Redshift).
     
  13. Nettdata

    Nettdata
    Expand Collapse
    Mr. Toast

    Reputation:
    2,863
    Joined:
    Feb 14, 2006
    Messages:
    25,737
    If you're REALLY looking to save cash, maybe even look to: Aurora Serverless.

    https://aws.amazon.com/rds/aurora/serverless/

    It's mysql instead of postgres, but that shouldn't matter for what you're doing.

    But it's fucking CHEAP... only pay for what you use, per second, unlike RDS where you're paying for an instance.

    Worth checking into if you're paying it yourself and it's not a crazy low latency, high perf PG gig.
     
  14. Nettdata

    Nettdata
    Expand Collapse
    Mr. Toast

    Reputation:
    2,863
    Joined:
    Feb 14, 2006
    Messages:
    25,737
    Personally I'd pick PG over Mysql any day, but for something like what you're looking at doing, the serverless, pay-per-second-of-use features would be worth "downgrading" to mysql.

    $0.02
     
  15. redbullgreygoose

    redbullgreygoose
    Expand Collapse
    Disturbed

    Reputation:
    2
    Joined:
    Oct 19, 2009
    Messages:
    498
    I know nothing about Dynamo or Redshift. I only have a moderate grasp on Python with some JavaScript and HTML. Yes, I will be paying for it myself. I am also self-taught. I'm enrolled in University for Comp Networking but I enjoy programming much more.
     
  16. redbullgreygoose

    redbullgreygoose
    Expand Collapse
    Disturbed

    Reputation:
    2
    Joined:
    Oct 19, 2009
    Messages:
    498
    MySQL it is then.
     
  17. Nettdata

    Nettdata
    Expand Collapse
    Mr. Toast

    Reputation:
    2,863
    Joined:
    Feb 14, 2006
    Messages:
    25,737
    Yeah, in your case, it's totally worth it.

    Again, you want the SERVERLESS version, not just RDS MySql...
     
  18. Nettdata

    Nettdata
    Expand Collapse
    Mr. Toast

    Reputation:
    2,863
    Joined:
    Feb 14, 2006
    Messages:
    25,737
    If anyone is at all interested in how to spin up a ton of the AWS services, feel free to ask. I oversee a lot of Lambda/Serverless and DB, EC2, S3, Redshift, Dynamo, SQS/SNS, etc services and lead teams that build that shit out to some pretty big, global scale.

    I also do a lot of stream processing and machine learning at scale... things like Kinesis and Kinesis Firehose, Sagemaker, Deeplens, Glue, Athena, Redshift/Redshift specturm, etc.

    Most of it is used for real-time fraud detection and alerting based on individual end-user behaviour, etc, but it's pretty cool shit.

    (It's basically the Apache Kafka/Spark stuff rolled out into AWS services).
     
  19. redbullgreygoose

    redbullgreygoose
    Expand Collapse
    Disturbed

    Reputation:
    2
    Joined:
    Oct 19, 2009
    Messages:
    498
    If you don't mind, can you give me a (very) basic explanation how severless programming works? Where does the data go? I see/hear it mentioned as offhand comments in tutorials all the time but where does the data get stored?
     
  20. Nettdata

    Nettdata
    Expand Collapse
    Mr. Toast

    Reputation:
    2,863
    Joined:
    Feb 14, 2006
    Messages:
    25,737
    Sure...

    "Normal" or classical app development means that you write an app, and then launch it in a server somewhere. That server is running an OS, an app server (like Apache), and then an application (like Django, etc). That means that the application is running 24x7 in that machine, and the machine is up and running 24x7.

    Serverless is different in that there is no OS, or machine that is spun up. Instead, there is a small piece of code (sometimes called a Lambda) that does one small specific piece of functionality. That code is uploaded to the cloud, and has an "activated by" or "triggered by" element, like an API call. You basically configure it so that when a specific REST endpoint is called, it runs that one piece of code that you've uploaded as the lambda. When it's done running, it goes away.

    It's used a lot with IOT (internet of things) programming where you might want to just capture small pieces of data and store them, for example... like a smart hydro meter, for example. Every 30 minutes, your meter will spin up, and then hit that REST endpoint. When that endpoint is called, it then runs that Lambda, and executes it with the data that is passed into it from that REST call. In some cases, that Lambda can be a Node.js snippet, which takes that data, parses the data, connects into a database, stores that data, and then shuts down and the Lambda/code-snippet is deleted.

    It's meant for more simplistic, very event-driven applications. It's designed to take advantage of all the unused, unallocated resources that AWS has that are sitting there doing nothing. You only pay fractions of pennies for each time the Lamda is run, rather than tens or hundres of dollars a month for a constantly running server.

    Serverless is able to scale way, way, WAY beyond the capacity of a normal instance that you'd spin up. For example, AWS EC2 has a number of instance sizes with various resource limits; memory, cpu, disk space, etc. You can spin up the box at a specific monthly cost for the use of those resources.

    Serverless let's you forget about that instance size... if you have 1 person hitting your API and triggering the lambda, you only get billed for that 1 person hitting that lambda. You can also have 10 million people hit that same endpoint and run that same lambda code 10 million times, simultaneously, so you can scale on demand so much easier than having to try and scale out EC2 instances to handle your scale, etc.

    It's pretty easy to understand how code snippets can be run as Lambdas, but the database stuff can be a bit harder to wrap your head around.

    That blog post I linked to earlier explains it, but it takes the storage of the database (which is stored in S3), and then only interacts with it when it needs to using that "on-demand" lambda like interaction, except with the DBMS (mysql). So when you need to store data, it grabs an available Mysql executable (that is running somewhere in their available resources in AWS), and then it connects quickly to your specific data files in S3, does it's thing, then spins down the Mysql executable. That means you don't have to pay for the instance to run mysql or postgres 24x7, it's only being spun up and used when it's actually being called.



    That's kind of a high overview... and I'm a bit drunk... so let me know if you need any clarification.

    This page gives you a bit of a high-level overview: https://aws.amazon.com/serverless/